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

Kev*_*vin 20 python gdal

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

extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory
compilation terminated
Run Code Online (Sandbox Code Playgroud)

但是,正确安装了GDAL并且头文件位于/usr/include/gdal/cpl_port.h.是否有一些GDAL的环境变量需要设置才能让pip找到头文件?

小智 22

正如在另一个线程中所建议的那样,在运行pip之前导出一些shell变量可以完美地工作.*_INCLUDE_PATH可以找到一条路径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
Run Code Online (Sandbox Code Playgroud)

  • pip3 install GDAL==$(gdal-config --version) 显式版本号应与您现有的 libgdal 版本匹配。 (2认同)

小智 8

摘自此评论,它直接解决了我的问题

\n\n
pip3 install GDAL==$(gdal-config --version) \n
Run Code Online (Sandbox Code Playgroud)\n\n

显式版本号应与您现有的 libgdal 版本匹配。\xe2\x80\x93

\n


Nei*_*ith 6

Tomyun的回答对我有用,条件是你必须确保安装的GDAL-dev apt-get版本与安装的版本相匹配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
Run Code Online (Sandbox Code Playgroud)

  • 我也使用Ubuntu 14.04.对我来说它没有用(我没有virtualenv).只有当我已经改变了过去的rowto这一个:sudo的PIP 3安装--global选项= build_ext --global选项= " - I/usr/include目录/ @中" GDAL == 1.10.0 (3认同)
  • pip3 install GDAL==$(gdal-config --version) 将适用于所有版本。 (2认同)

lep*_*rem 5

使用PIP:

pip install --no-install GDAL
Run Code Online (Sandbox Code Playgroud)

然后进入ENV/build/GDAL

python setup.py build_ext --include-dirs=/usr/include/gdal
pip install --no-download GDAL
Run Code Online (Sandbox Code Playgroud)

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

使用Buildout:

[gdal-bindings]
recipe = zc.recipe.egg:custom
egg = GDAL==1.9.1
include-dirs = /usr/include/gdal
library-dirs = /usr/lib
Run Code Online (Sandbox Code Playgroud)