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.

6 Answers 6

8

Try this,

pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`    
3
  • It works well in my Mac with Python 3.8.3 (default, Jul 2 2020, 11:26:31) Anaconda. Successfully installed GDAL-3.2.0
    – Hua Zhang
    Nov 19, 2020 at 0:18
  • @Saroj, would appreciate it if you could explain why this works as it does or point to an explanation somewhere? Nov 19, 2020 at 2:24
  • Worked for me, but needed sudo apt install libgdal-dev first.
    – khaverim
    Aug 25, 2021 at 14:53
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
3
  • I have done the above but now getting different error and also noticed what you mention above regarding two python (27 and 34)
    – Asanda
    Jan 31, 2017 at 6:27
  • I removed the second python but still not working...
    – Asanda
    Jan 31, 2017 at 7:50
  • You're a wizard Har.. Jimmy
    – Akaisteph7
    Jun 24, 2022 at 23:22
2

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

1
  • 2
    Ok, but this question is for Windows OS (check tag osgeo4w). Your answer solves the problem in this OS?
    – aldo_tapia
    Sep 6, 2017 at 19:35
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

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.

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.

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.