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
Try this,
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
-
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 Commented 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? Commented Nov 19, 2020 at 2:24
-
Worked for me, but needed
sudo apt install libgdal-dev
first.– khaverimCommented Aug 25, 2021 at 14:53
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
-
I have done the above but now getting different error and also noticed what you mention above regarding two python (27 and 34)– AsandaCommented Jan 31, 2017 at 6:27
-
-
Got the same problem. I fixed ir by installing python-gdal using synaptic with my Debian Jessie
-
2Ok, but this question is for Windows OS (check tag osgeo4w). Your answer solves the problem in this OS? Commented Sep 6, 2017 at 19:35
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
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.
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.