39

I'm trying to install GDAL through pip. But I'm getting this error:

extensions/gdal_wrap.cpp:3089:27: fatal error: cpl_vsi_error.h: No such     file or directory
 #include "cpl_vsi_error.h"
                           ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I used these commands:

sudo apt-get install libgdal-dev
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL

Can anyone tell me how to install it ?

Rahul
  • 3,208
  • 8
  • 38
  • 68
  • possible duplicate of this? http://stackoverflow.com/questions/37294127/python-gdal-2-1-installation-on-ubuntu-16-04 – giosans Jul 28 '16 at 08:07

6 Answers6

27

Check that you installed GDAL using this command

gdal-config --version

Then run this commands:

pip download="some_path" GDAL
cd some_path
tar -xvzf GDAL-<version>.tar.gz
cd GDAL-<version>
python setup.py build_ext --include-dirs=/usr/include/gdal/
python setup.py install
Dima Kudosh
  • 7,126
  • 4
  • 36
  • 46
  • 2
    for anyone else stuck, depending on how you installed GDAL you might have a different location for the missing header file. i installed via kyngchaos and for me the correct path was: `--include-dirs=/Library/Frameworks/GDAL.framework/Versions/2.1/Headers/` – Owen Dec 05 '16 at 14:18
  • 71
    `pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')` – nicerobot Jan 11 '17 at 23:47
  • `pip3 download "$HOME/Downloads/" GDAL` `ERROR: Directory '/home/leonardo/Downloads/' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.` – Leonardo Guerreiro Sep 16 '20 at 14:06
  • I was instructed to download the "core" and the "python bindings" binaries to my computer. Are these all I need to download? having done so, the command `gdal-config --version ` produces an error saying it is not recognized as a command as per my question [over here](https://stackoverflow.com/questions/71667487/gdalinfo-not-recognized-after-installing-and-setting-path-variables) – Max Duso Apr 01 '22 at 22:54
24
pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')

This is a copy-paste of this comment by nicerobot, that at this time received more up votes than all currently posted answers combined.

As far as I can tell, it asks pip to install the pip package of the same version as the installed gdal system package.

Dominykas Mostauskis
  • 7,797
  • 3
  • 48
  • 67
17

On my MacBook, the update/fresh install of GDAL using this approach with homebrew worked out fine. The problem on my Mac was that I apparently had an old GDAL version installed and wasn't able to update with brew upgrade gdal because of the above error message.

Solution in short:

brew unlink gdal
brew tap osgeo/osgeo4mac && brew tap --repair
brew install jasper netcdf # gdal dependencies
brew install gdal2 --with-armadillo --with-complete --with-libkml --with-unsupported
brew link --force gdal2

Verification:

$> gdal-config --version
2.1.3
$> gdal-config --libs
-L/usr/local/Cellar/gdal2/2.1.3_3/lib -lgdal
$> gdal-config --cflags
-I/usr/local/Cellar/gdal2/2.1.3_3/include
felice
  • 1,185
  • 1
  • 13
  • 27
  • 4
    Had to do a mix of some of the above answers but got this to work on my Mac running el capitan! Before installing with felice's brew answer I had to run `export C_INCLUDE_PATH=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7/ ` After the brew installs I had to run: `pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')` – imapotatoe123 May 23 '17 at 14:51
  • 2
    You need to do the above "Solution in short" first, then do the "verification" and lastly do `pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')` by imapotoatoe123. – Shaun Stanislaus Jul 31 '17 at 01:32
  • 1
    Worked with fix from @imapotatoe123 – Subspacian Mar 13 '18 at 12:22
  • 1
    Everytime I read `awk -F` here, it reads in my mind as awkward as F*. :D – Sulphur Mar 11 '20 at 21:45
4

I had to include the header files as well to successfully install gdal:

sudo pip3 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') --global-option=build_ext --global-option="-I/usr/include/gdal"

Note: Using Python 3 and gdal was already installed on centOS

scottlittle
  • 18,866
  • 8
  • 51
  • 70
1

Firstly, activate the environment where you want gdal to be installed. Then simply try command:

[conda install -c conda-forge gdal]

Refer to this link. Hope this helps!!

0

Quoting @nicerobot comment, and adding a command to make it work in case you run into

ERROR: Could not find a version that satisfies the requirement GDAL

sudo apt install libgdal-dev
pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')
Tms91
  • 3,456
  • 6
  • 40
  • 74