Python 安装GDAL时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38630474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:14:07  来源:igfitidea点击:

Error while installing GDAL

pythonpipgdal

提问by Rahul

I'm trying to install GDAL through pip. But I'm getting this error:

我正在尝试通过 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

I used these commands:

我使用了这些命令:

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

Can anyone tell me how to install it ?

谁能告诉我怎么安装?

采纳答案by Dima Kudosh

Check that you installed GDAL using this command

检查您是否使用此命令安装了 GDAL

gdal-config --version

Then run this commands:

然后运行这个命令:

pip install --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

回答by felice

On my MacBook, the update/fresh install of GDAL using thisapproach with homebrew worked out fine. The problem on my Mac was that I apparently had an old GDAL version installed and wasn't able to update with brew upgrade gdalbecause of the above error message.

在我的 MacBook 上,使用这种方法和自制软件更新/全新安装 GDAL效果很好。我的 Mac 上的问题是我显然安装了旧的 GDAL 版本,但brew upgrade gdal由于上述错误消息而无法更新。

Solution in short:

简而言之解决方案:

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

Verification:

确认:

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

回答by Dominykas Mostauskis

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

This is a copy-paste of this commentby nicerobot, that at this time received more up votes than all currently posted answers combined.

这是nicerobot对这条评论的复制粘贴,此时收到的票数比所有当前发布的答案总和还要多。

As far as I can tell, it asks pip to install the pip package of the same version as the installed gdal system package.

据我所知,它要求 pip 安装与安装的 gdal 系统包相同版本的 pip 包。

回答by scottlittle

I had to include the header files as well to successfully install gdal:

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

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

Note: Using Python 3 and gdal was already installed on centOS

注意:使用 Python 3 并且在centOS 上已经安装了 gdal