I used to work with gdal in my ubuntu but after installing geany it stoped working and when I try running my code I get the error. ModuleNotFoundError: No module named '_gdal'

this is what the sample code says:

$ python3 -c "from osgeo import gdal; print(gdal.version)" Traceback (most recent call last): File "/home/vahid/.local/lib/python3.10/site-packages/osgeo/init.py", line 29, in swig_import_helper return importlib.import_module(mname) File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 674, in _load_unlocked File "", line 571, in module_from_spec File "", line 1176, in create_module File "", line 241, in _call_with_frames_removed ImportError: libgdal.so.30: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/home/vahid/.local/lib/python3.10/site-packages/osgeo/init.py", line 45, in _gdal = swig_import_helper() File "/home/vahid/.local/lib/python3.10/site-packages/osgeo/init.py", line 42, in swig_import_helper return importlib.import_module('_gdal') File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ModuleNotFoundError: No module named '_gdal'

I also checked pip list and found that I have GDAL 3.4.1 and python3 --version shows Python 3.10.12

  • Thank you so much @user2856 . Your comment was really helpful and it was my answer . I think it would be helpful for others if you post it as answer to this question. Commented Apr 15 at 9:41
  • OK, answer added.
    – user2856
    Commented Apr 15 at 9:54

1 Answer 1


GDAL is distributed on pypi as a source only package. Don't pip install gdal unless you know what you are doing and have installed the appropriate libgdal and development tool chain including the gdal (and optional numpy) headers package.

Instead, clean up the broken pip install

pip uninstall gdal
## OR
rm -rf /home/vahid/.local/lib/python3.10/site-packages/osgeo 

and then install from your package manager

sudo apt install gdal-bin python3-gdal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.