python - GDAL安装错误“错误:命令'x86_64-linux-gnu-gcc'失败,退出状态为1”
问题描述
我正在尝试使用 python 安装 GDAL。但它失败并出现错误。
我使用的命令是pip install GDAL
.
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-2.7/extensions/gdal_wrap.o -std=c++11 -I/usr/include/gdal
extensions/gdal_wrap.cpp:3177:27: fatal error: cpl_vsi_error.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
和
----------------------------------------
Failed building wheel for GDAL
Running setup.py clean for GDAL
Failed to build GDAL
Installing collected packages: GDAL
Running setup.py install for GDAL ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_spRXy/GDAL/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-NxpUaO-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying gdal.py -> build/lib.linux-x86_64-2.7
...
creating build/temp.linux-x86_64-2.7/extensions
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-2.7/extensions/gdal_wrap.o -std=c++11 -I/usr/include/gdal
extensions/gdal_wrap.cpp:3177:27: fatal error: cpl_vsi_error.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_spRXy/GDAL/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-NxpUaO-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_spRXy/GDAL/
我已经尝试过了sudo apt-get install build-essential
,但仍然出现同样的错误。
解决方案
这是我发现有效的答案:
“您可能必须将 gdal 版本更改为主机上安装的版本。所以我必须这样做,因为我的主机上有 gdal==1.11.2:”
pip install gdal==1.11.2 --global-option=build_ext --global-option="-I/usr/include/gdal/"
应该将 1.11.2 更新到您的 gdal_version 的位置,可以在文件的行# define GDAL_RELEASE_NAME
中找到/usr/include/gdal/gdal_version.h
(至少在我运行 Kubuntu 的系统上)。
使用 Basaks 的这个答案链接到原始github 页面,在 Craicerjack 上面的评论中提到。
推荐阅读
- python-3.x - PyAutoGUI 问题超出语法(time.sleep)
- icons - 如何更改 PrimeNG-Dropdown 的图标
- json - json 中的 ia 首选是否具有嵌套对象
- javascript - 以函数式协变方式使用 Array.prototype.map
- redux - Flutter 中的 Widget 间通信(使用 Redux)
- javascript - 在对象数组中循环,但不打印?
- c++ - 如何创建可供 src/ 代码和 lib/ 库访问的全局对象?
- c# - 选择提示问题
- javascript - vue-router:嵌套命名视图问题。附加组件不可见
- magento - 我需要在我的 Magento 2.3 上添加其他字段来示例导出 csv 文件