[GIS] GDAL conda install on Mac OS trouble

anacondacondagdalosgeopython

I'm trying to install gdal on my new computer in the anaconda environment using conda but having issues. All I've done so far is install Anaconda for python 3.6 and install gdal as described here + a few other libraries using both conda and pip.

Trouble is when I try to run from "osgeo import gdal" the iPython console in spyder I get this error, which I'm not smart enough to interpret on my own:

Traceback (most recent call last):

File "", line 1, in
from osgeo import gdal

File "/anaconda/lib/python3.6/site-packages/osgeo/init.py", line 21, in
_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/libicui18n.58.dylib
Referenced from: /anaconda/lib/libgdal.20.dylib
Reason: image not found

Is there a problem with the conda install of gdal I'm using, or am I missing a piece?

Is there a different/easier way to start using gdal than this?

Best Answer

I've found that the dependency versions are a bit messed up. GDAL is relying on there being older versions of certain libraries, but newer ones are installed by default. I've managed to get it working by forcing older versions of some of the dependencies. A minimal working environment.yml looks like this:

name: gis_project
channels:
  - conda-forge
  - defaults
dependencies:
  - gdal=2.3.1
  - ncurses=5.9=10
  - libspatialite=4.3.0a=19

In a new directory, run conda env create, activate the environment conda activate gis_project and check it works.

Related Question