Reputation: 1133
I'm trying to install gdal from pip pip install gdal
inside a virtual environment (Ubuntu). It fails because it cannot find cpl_port.h
extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory
compilation terminated
However GDAL is installed correctly and the header file is located at /usr/include/gdal/cpl_port.h
. Is there some environment variable for GDAL that needs to be set in order for pip to find the header files?
Upvotes: 24
Views: 34103
Reputation: 136
Taken from this comment, it solved my issue directly
pip3 install GDAL==$(gdal-config --version)
Explicit version number should match your existing libgdal version. –
Upvotes: 8
Reputation: 742
This is what worked for me:
I had to get the latest hearder versions for installing gdal 2.2.4 through pip:
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install libgdal-dev
Before that, I was getting extensions/gdal_wrap.cpp:3172:27: fatal error: cpl_vsi_error.h: No such file or directory
, even when including the correct "include" path to pip.
The the pip installation (in a virtualenv):
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" gdal
Upvotes: 1
Reputation: 6861
I was also getting this error when test installing in a virtual environment a package of mine that depends on GDAL. In this case the solution is to change the dependecy from GDAL
to pygdal
in the install_requires
parameter in setup.py
. Like so:
install_requires=['pygdal'],
Upvotes: 1
Reputation: 398
As suggested in the other thread, exporting some shell variables before running pip worked flawlessly. A path for *_INCLUDE_PATH
can be found with gdal-config --cflags
.
# GDAL library must have been installed
sudo apt-get install libgdal-dev
# Set up pip and/or virtualenv stuff
...
# Now install Python binding for GDAL
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL
Upvotes: 26
Reputation: 333
Tomyun's answer worked for me, with the proviso that you have to ensure that the version of GDAL-dev installed via apt-get
matches the version being installed by pip
.
For Ubuntu 14.04, the commands are:
# GDAL library must have been installed
sudo apt-get install libgdal-dev
# Set up pip and/or virtualenv stuff
...
# Now install Python binding for GDAL
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip3 install GDAL=1.10.0
Upvotes: 8
Reputation: 1025
Using PIP :
pip install --no-install GDAL
Then cd into ENV/build/GDAL
python setup.py build_ext --include-dirs=/usr/include/gdal
pip install --no-download GDAL
(Source: http://ubuntuforums.org/showthread.php?t=1769445)
Using Buildout :
[gdal-bindings]
recipe = zc.recipe.egg:custom
egg = GDAL==1.9.1
include-dirs = /usr/include/gdal
library-dirs = /usr/lib
Upvotes: 5