Search code examples
pythonpipcondagdal

"from osgeo import gdal" error not working on ubuntu 18.04.5


I installed gdal from pip as well as conda forge that is completed. but when I import it pushes an error. Can anyone guides me the way forward.

python -c "from osgeo import gdal"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/hmahmad/anaconda3/envs/pt/lib/python3.8/site-packages/osgeo/__init__.py", line 26, in <module>
    _gdal = swig_import_helper()
  File "/home/hmahmad/anaconda3/envs/pt/lib/python3.8/site-packages/osgeo/__init__.py", line 22, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
  File "/home/hmahmad/anaconda3/envs/pt/lib/python3.8/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/hmahmad/anaconda3/envs/pt/lib/python3.8/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libiconv.so.2: cannot open shared object file: No such file or directory

System specs:

  1. ubuntu 18.04.5
  2. python 3.8.5 and when I install it again it says
pip install GDAL
Requirement already satisfied: GDAL in /home/hmahmad/anaconda3/envs/pt/lib/python3.8/site-packages (2.3.3)

Solution

  • Solved the issue by installing Rasterio library with conda

    conda install -c conda-forge rasterio
    

    I dont know whats the connection behind but it seems like it installed all the relevant dependant libraries and it make gdal work.