I'm trying to install GDAL osgeo lib into Python 3.6 on Debian Stretch

I installed neccessary packages like:

sudo apt-get update && sudo apt-get install -y \
  binutils \
  libproj-dev \
  gdal-bin \
  libgdal-dev \
  python3-gdal \
  python3-pip \
  python-numpy \
  python-dev \

That installation works for Python 2.7 and Python <= 3.5.

But in interpreter I'm receiving following error:

>>> import osgeo
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'osgeo'

Do you know any solution for fixing that?


I solved this problem by installing via Python PIP pygdal package. Firstly you need to check Gdal version installed on the machine, and install proper pygdal.

$ gdalinfo --version
GDAL 2.1.3, released 2017/20/01
$ pip install "pygdal>=2.1.2,<2.1.3"
  • 1
    I think it should read 'pip install "pygdal>=2.1.2,<2.1.3"'. This work for me, thanks! – StephenT Jun 10 '19 at 23:13
  • If you run into error: [Errno 2] No such file or directory: 'gdal-config', install libgdal-dev using your distribution package manager. – Skippy le Grand Gourou Nov 4 '20 at 20:29

This may works

pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`    
  1. Try locating the directory where your gdal python bindings are installed (e.g., search for osgeo.py).
  2. Add that path to your python's sys.path, which can be done by editing the .pth file under your python's sitepackage folder. I suggest simply inserting that directory to sys.path first to see whether it works.

I did this on Mac OS and it worked for python 3.6.

  • Can you specify sys.path location path on your OS or a programmatic way to append the line ? Something like import sys; sys.path.append('path/to/osgeo.py') ??? (I started python 15mins ago, just reading online docs and reporting here.) – Hugolpz Sep 7 '20 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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