通过pip安装时Python GDAL包缺少头文件

2024-05-21 00:01:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从虚拟环境(Ubuntu)中的pip pip install gdal安装gdal。它失败,因为它找不到cpl_port.h

extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory
compilation terminated

但是,GDAL安装正确,头文件位于/usr/include/gdal/cpl_port.h。是否需要为GDAL设置一些环境变量,以便pip查找头文件?


Tags: installpip头文件portubuntu虚拟环境extensionserror
3条回答

正如the other thread中所建议的,在运行pip之前导出一些shell变量可以完美地工作。可以使用gdal-config --cflags找到*_INCLUDE_PATH的路径。

# 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

Tomyun的回答对我有效,但前提是必须确保通过apt-get安装的GDAL dev版本与通过pip安装的版本匹配。

对于Ubuntu 14.04,命令是:

# 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

使用PIP:

pip install --no-install GDAL

然后cd到ENV/build/GDAL

python setup.py build_ext --include-dirs=/usr/include/gdal
pip install --no-download GDAL

(来源:http://ubuntuforums.org/showthread.php?t=1769445

使用构建:

[gdal-bindings]
recipe = zc.recipe.egg:custom
egg = GDAL==1.9.1
include-dirs = /usr/include/gdal
library-dirs = /usr/lib

相关问题 更多 >