21

I have installed GDAL and checked on the command line, it is working and when I run the gdal2tiles.py on the command line it works but when I run the same file gdal2tiles.py with python IDLE, I get "No module named 'osgeo'" error. Can you assist.

Asanda
  • 293
  • 2
  • 3
  • 7

6 Answers6

8

Try this,

pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`    
Saroj Rai
  • 259
  • 3
  • 6
6

This sounds like you have multiple python installations, and GDAL is installed on one and not the other.

Try the following (which I have based upon this). Create a text file within your python installation site packages folder C:\Python27\Lib\site-packages called usrlocal.pth. In this text file insert one line giving the path to your second python installation site packages folder which features the GDAL install, for example:

C:\OSGeo4W\apps\Python27\Lib\site-packages
JimT
  • 2,383
  • 2
  • 10
  • 22
2

Got the same problem. I fixed ir by installing python-gdal using synaptic with my Debian Jessie

1

Another possibility is using easy_install from Python:

easy_install gdal

Preferably install numpy for array operations first:

easy_install numpy

For more information about easy_install/setup tools: https://setuptools.readthedocs.io/en/latest/easy_install.html

Alex
  • 11
  • 1
0

I was struggling with this as well. Finally, I created a new virtualenv using Anaconda following this: How to Install PyTorch on Windows Step by Step.

Next, I just used anaconda prompt to install GDAL, i.e. typed: conda install GDAL. It worked! Pycharm recognises OSGeo now.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Ewa
  • 1
0

For GDAL 3.7.1 built from source using CMake on Ubuntu 20.04, the following worked for me using Python 3.8.10.

sudo apt-get install python3-gdal

I was then able to do from osgeo import gdal for my application.

Dennis
  • 1
  • 1