简体   繁体   中英

unable to import gdal on mac, installed through anaconda

I'm getting the following error when I try to import gdal:

>>> from osgeo import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda/lib/python3.6/site-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "//anaconda/lib/python3.6/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
  File "//anaconda/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "//anaconda/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(//anaconda/lib/python3.6/site-packages/osgeo/_gdal.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libgdal.20.dylib
  Referenced from: //anaconda/lib/python3.6/site-packages/osgeo/_gdal.cpython-36m-darwin.so
  Reason: image not found

I've tried uninstalling and reinstalling (it's installed with conda-forge), updating, and checking to make sure those files along the paths exists, but nothing seems to work! I also looked at a thread that suggested checking the .condarc file but can't find one.

See the last comment on this page. This is a known issue. To save you the click:

gdal depends on a huge number of c-libs that need to be pinned down to specific versions to avoid software breakage by mixing versions.

The problem is that different channels pin to different versions. That means you need to "stay" within a "trusted/consistent" pinning scheme.

The Anaconda distribution brings a lot of pre-installed software and, even by adding conda-forge as the preferred channel (placing it on top of defaults), will be hard to get that consistent installation.

We recommend using miniconda and creating envs to "encapsulate" the different cases and get a more stable installation. (Or, like I mention above, if you don't need external channels you can use only defaults.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM