Rahul
Rahul

Reputation: 3396

Error while installing GDAL

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 ?

Upvotes: 39

Views: 49416

Answers (6)

Tms91
Tms91

Reputation: 4214

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}')

Upvotes: 0

Anupama Gautam
Anupama Gautam

Reputation: 9

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!!

Upvotes: 1

Dima  Kudosh
Dima Kudosh

Reputation: 7386

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

Upvotes: 28

scottlittle
scottlittle

Reputation: 20942

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

Upvotes: 4

Dominykas Mostauskis
Dominykas Mostauskis

Reputation: 8135

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.

Upvotes: 24

felice
felice

Reputation: 1363

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

Upvotes: 17

Related Questions