Python GDAL package missing header file when insta

2019-01-14 20:58发布

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?

标签: python gdal
6条回答
欢心
2楼-- · 2019-01-14 21:39

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
查看更多
We Are One
3楼-- · 2019-01-14 21:43

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
查看更多
对你真心纯属浪费
4楼-- · 2019-01-14 21:43

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'],

查看更多
欢心
5楼-- · 2019-01-14 21:51

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
查看更多
Rolldiameter
6楼-- · 2019-01-14 21:53

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
查看更多
Ridiculous、
7楼-- · 2019-01-14 21:55

try to do: brew install gdal

after that try again.

查看更多
登录 后发表回答