Maxim L Maxim L - 1 year ago 294
Python Question

Cannot use GDAL with Python 3.3 or 3.4 in Conda

I am desperately trying to get GDAL to work in my Python 3.4 Conda environment, but am getting an error. I have tried to install GDAL using Python 2.7, 3.3, 3.4, and 3.6 to test things out and GDAL will only work in 2.7 and 3.6.
I am running on Debian 8.8 Jessie and have upgraded my Conda.

Here are the steps I followed:

$ conda create -n py34 python=3.4

$ conda install -n py34 gdal -c conda-forge


To test, I then do:

$ source activate py34
$ python -c 'import gdal'


When done for Python 2.7 and 3.6, it works without a problem. However, I need to run GDAL in a 3.4 environment because of compatibility with an other library.

For Python 3.3 (just in case it's useful) I get:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/username/anaconda3/envs/py33/lib/python3.3/site-packages/gdal.py", line 2, in <module>
from osgeo.gdal import deprecation_warn
File "/home/username/anaconda3/envs/py33/lib/python3.3/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/home/username/anaconda3/envs/py33/lib/python3.3/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "/home/username/anaconda3/envs/py33/lib/python3.3/imp.py", line 188, in load_module
return load_dynamic(name, filename, file)

ImportError: libcom_err.so.3: cannot open shared object file: No such file or directory


And similarly for Python 3.4:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/username/anaconda3/envs/py34/lib/python3.4/site-packages/gdal.py", line 2, in <module>
from osgeo.gdal import deprecation_warn
File "/home/username/anaconda3/envs/py34/lib/python3.4/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/home/username/anaconda3/envs/py34/lib/python3.4/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "/home/username/anaconda3/envs/py34/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)

ImportError: libicui18n.so.56: cannot open shared object file: No such file or directory

Answer Source

Moved solution from question to answer:

EDIT: problem solved!

The solution was in the following thread: Issue when imoporting GDAL : ImportError, Library not loaded, Image not found

After adding the conda-forge to my .condarc, I did:

$ conda create -n TEST_GDAL python=3.4 gdal
$ conda install -n TEST_GDAL -f jpeg=8
$ conda install -n TEST_GDAL libgdal

which downgraded some packages and installed GDAL 2.2.1

Hopefully, the downgrade won't interfere with other packages!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download