4

I have been trying to install python gdal with OSGEO for some time now with no success. I have removed. I have tried with "Express and Advance" as suggested by OSGEO4W site.

The error is always "No module named 'osgeo' or gdal", the command line also does not recognise an internal program.

5
  • If it is in Windows try to run it in Osgeo shell rather than normal command prompt
    – S. Thiyaku
    Feb 3, 2017 at 7:30
  • I have tried but still getting the same message
    – Asanda
    Feb 3, 2017 at 8:26
  • Check whether the path is correct? echo %PATH% command list all paths in command prompt. Check python path also ?
    – S. Thiyaku
    Feb 3, 2017 at 10:54
  • What python version do you have? Feb 6, 2017 at 7:34
  • The echo %PATH% also includes paths for previously installed python versions, I removed python 3.4 then installed 2.7
    – Asanda
    Feb 6, 2017 at 11:04

6 Answers 6

2

Summerizing the 4 steps from the answer of Khoa:

  • go to this site to download appropriate windows binaries (once you've clicked on the appropriate version of GDAL bianaries, select GDAL core to download the main fucntionnalities).

  • install GDAL with default (or not ?) settings

  • return to the page where you got GDAL core and download GDAL python bindings to work with your python version

  • install python bbindings

2

For ubuntu, run the following:

sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL

Source: https://mothergeo-py.readthedocs.io/en/latest/development/how-to/gdal-ubuntu-pkg.html

Also potentially of interest, the GDAL binaries https://gdal.org/download.html

1

Follow the 4-step instruction on this site: https://sandbox.idre.ucla.edu/sandbox/tutorials/installing-gdal-for-windows

I found this site after hours of failing in installing osgeo.

Good luck.

1
  • 5
    Thanks for providing this answer. Can you summarize the 4 steps on your link. In case the link changes in the future, there is some record of what the user must to if they encounter the same issue. Aug 18, 2017 at 16:05
1

For ubuntu:

sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install libgdal-dev gdal-bin

# Sanity, check the version. For ubuntu 18.04, it's probably 2.4.2
ogrinfo --version

export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal

sudo apt install python3.8-dev. <-- NOTE the python version should match yours
pip3 install GDAL==$(ogrinfo --version | cut -d' ' -f2 | cut -d',' -f1)


# If the above doesn't work, input the version manually from ogrinfo
# pip3 install GDAL==2.4.2 (Or any other version received from ogrinfo)
0

On MacOSX:

  1. Conda installation: (Easy mode)

From https://anaconda.org/conda-forge/gdal

Assuming you have conda installed, conda install -c conda-forge gdal That's it you're done, conda installs the underlying gdal binaries for you.

  1. Using brew/pip
brew install gdal # This installs the underlying binaries

pip install gdal  #(inside your venvs or whatever for python bindings)

You may get clang errors during the pip install, in which case you probably don't have the latest xcode build tools.

There is a longwided reason for why this occurs, but tl;dr go and download the latest version of the command line tools for xcode https://developer.apple.com/download/all/?q=xcode

0

1

For ubuntu: 20.04 LTS

sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install libgdal-dev gdal-bin

####Sanity, check the version. For ubuntu 18.04, it's probably 2.4.2 ogrinfo --version

export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal

sudo apt install python3.8-dev. <-- NOTE the python version should match yours pip3 install GDAL==3.3.2

NOTE THAT IF THE pip3 install GDAL=3.3.2 DOES NOT WORK FOR ANACONDA(FOR ME WHEELS WERE CREATING ISSUE) THEN RUN THE BELOW:

conda install -c conda-forge gdal==3.3.2 (Or any other version received from ogrinfo)

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.