ryurruuggbbyy
ryurruuggbbyy

Reputation: 39

Import Gdal not working

I used conda install -c conda-forge gal to install the GDAL package. However, I got a following error in importing the package.

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

I tried the followings but they didn't work for me:

conda upgrade numpy

conda install libpng

Does anyone know what I should do?

Upvotes: 4

Views: 4665

Answers (4)

Rick
Rick

Reputation: 45291

I use anaconda as well and have also had issues installing GDAL in the past. Instead I usually download a wheel from Christoph Gohlke and do pip install <file_name>.whl and it works.

Upvotes: 3

milad
milad

Reputation: 214

I had the same problem in installing GDAL package on Conda. Finally this strange solution worked.

I installed a fresh anaconda. I created a new environment on the default python. Finally, I installed only shapely, psycopg2, and fiona in one command with no version specification and then I saw that GDAL is also installed and it is working!!!

The Installed versions are:

   Python    = 3.12.3

1- Shapely   = 2.0.1
2- Fiona     = 1.9.5
3- Psycopg2  = 2.9.9
4- GDAL      = 3.6.2

I am able to import GDAL and work with it even if I did not mention it in the command of conda to install it!!

Upvotes: 0

Ashin Shanly
Ashin Shanly

Reputation: 31

Try "from osgeo import gdal", hope it helps!

Upvotes: 2

megallinic
megallinic

Reputation: 1

I think you could do either of the following to make GDAL work:

1) Install the latest version of OSGeo4W and install same version of python as explained in this answer.

2) Download a free version of Enthought canopy from here. Make sure you download the appropriate version based on your platform. Then using their package manager, search for "gdal" in the search bar. Install the gdal package. Then you can either use the canopy IDE or use this python environment with any other python IDE like Wing (my favourite) by giving the python path of enthought canopy. You can install as many packages as you want from the package manager which are available. For the unavailable ones, you can use the canopy command prompt which is configured with pip.

I personally prefer the 2nd way.

Upvotes: -1

Related Questions