0

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.

Andrey Portnoy
  • 1,430
  • 15
  • 24

1 Answers1

0

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.)

Andrey Portnoy
  • 1,430
  • 15
  • 24
  • ok so I've now done the following in terminal: conda create -n newenv python=3.6 gdal source activate newenv if I'm coding in spyder does this now mean I have to open spyder from within that new environment? or is there another way? – E Schreiber Aug 08 '17 at 19:54
  • @ESchreiber Correct, you need to either run it from there, or reinstall it in the environment. See [here](https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment/30170469) and [here](https://stackoverflow.com/questions/34217175/spyder-does-not-run-in-anaconda-virtual-environment-on-windows-10). – Andrey Portnoy Aug 08 '17 at 19:58
  • unfortunately I'm still getting a similar error in my new environment (newenv). "ImportError: dlopen(/Users/echreiber/anaconda/envs/newenv/lib/python3.6/site-packages/osgeo/_gdal.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libicui18n.58.dylib Referenced from: /Users/eschreiber/anaconda/envs/newenv/lib/libgdal.20.dylib Reason: image not found" – E Schreiber Aug 08 '17 at 21:02
  • @ESchreiber gdal requires very specific library versions. Try to force-install the exact versions gdal is looking for using `conda install -f library_name=library_version` for each library that you are getting an error for. – Andrey Portnoy Aug 08 '17 at 21:15
  • @ESchreiber Also, see [here](https://github.com/conda-forge/gdal-feedstock/issues/111). – Andrey Portnoy Aug 08 '17 at 21:17