4

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?

sorryMike
  • 191
  • 1
  • 2
  • 9

3 Answers3

5

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"
sorryMike
  • 191
  • 1
  • 2
  • 9
3

This may works

pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`    
Saroj Rai
  • 259
  • 3
  • 6
1
  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.

yimcai
  • 41
  • 4
  • 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 07 '20 at 08:29