安装GDAL时出现错误

39

我正在尝试通过pip安装GDAL。但是我遇到了这个错误:

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

我使用了以下指令:

sudo apt-get install libgdal-dev
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL

有人能告诉我如何安装它吗?


这可能是一个重复的问题?https://dev59.com/wVoU5IYBdhLWcg3wnXxO - giosans
6个回答

28

请使用以下命令检查您是否已安装GDAL:

gdal-config --version

然后运行以下命令:

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

2
对于其他遇到类似问题的人,根据你安装GDAL的方式,缺失头文件的位置可能不同。我是通过kyngchaos安装的,对我来说正确的路径是:--include-dirs=/Library/Frameworks/GDAL.framework/Versions/2.1/Headers/ - Owen
71
使用以下命令安装特定版本的GDAL:pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')该命令将根据当前系统中已安装的GDAL版本,自动选择对应的版本进行安装。 - nicerobot
pip3 download "$HOME/Downloads/" GDAL ERROR: Directory '/home/leonardo/Downloads/' is not installable. Neither 'setup.py' nor 'pyproject.toml' found. - Leonardo Guerreiro
我被指示将“核心”和“Python绑定”二进制文件下载到我的计算机上。这些是我需要下载的全部内容吗?在这样做之后,命令gdal-config --version会产生一个错误,说它不被识别为命令,正如我在这里所问的那样。 - Max Duso

24
pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')

这是 nicerobot 的评论this comment的复制粘贴,目前获得的赞数比所有当前发布的答案加起来还要多。
据我所知,它要求 pip 安装与已安装的 gdal 系统包相同版本的 pip 包。

17

在我的MacBook上,使用这个通过homebrew的方法更新/重新安装GDAL很顺利。问题在于我的Mac上显然安装了旧版GDAL,因此无法通过brew upgrade gdal进行更新,因为出现了上述错误消息。

简要解决方案:

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

验证:

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

4
我必须结合以上答案的一些方法,但最终在我的Mac电脑上安装成功并运行el capitan系统!在使用Felice的brew方案之前,我需要运行以下命令:export C_INCLUDE_PATH=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7/ 安装完brew后,我还需要运行:pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') - imapotatoe123
2
你需要先完成上面的“简短解决方案”,然后进行“验证”,最后执行 pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}'),作者是 imapotoatoe123。 - Shaun Stanislaus
1
与 @imapotatoe123 一起使用修复。 - Subspacian
1
每当我在这里读到 awk -F 时,我脑海中就会读成awkward as F*。 :D - Sulphur

4

我必须同时包含头文件才能成功安装 gdal:

sudo pip3 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') --global-option=build_ext --global-option="-I/usr/include/gdal"

注意:使用Python 3并且gdal已在CentOS上安装。

1
首先,激活您想要安装gdal的环境。然后只需尝试以下命令:
[conda install -c conda-forge gdal]

请参考此链接

希望这有所帮助!


0
引用@nicerobot comment,并添加一个命令以使其在遇到以下错误时正常工作:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接