阿尔派安装Gdal编译失败 - "错误:命令'gcc'以1的退出状态失败"

3

我正在尝试在Alpine Docker环境中安装Gdal。 我已经安装了Gdal的依赖项,这一步进行得很顺利。

RUN apk add --no-cache gcc build-base /gdal/gdal-dev-2.4.0-r1.apk /gdal/gdal-2.4.0-r1.apk /gdal/geos-3.7.1-r0.apk /gdal/libcrypto1.1-1.1.1b-r1.apk

我运行了命令 "pip install gdal"

它下载了GDAL-3.0.0.tar.gz,但在安装时出现错误。

记录已被清理。

Building wheels for collected packages: gdal
  Building wheel for gdal (setup.py) ... error
  ERROR: Complete output from command /usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-hlldvrpz/gdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-dj2y5pji --python-tag cp37:
  ERROR: WARNING: numpy not available!  Array support will not be enabled
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  copying gdal.py -> build/lib.linux-x86_64-3.7
  copying ogr.py -> build/lib.linux-x86_64-3.7
...
...
...
running build_ext
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/local/include/python3.7m -I. -I/usr/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o
  building 'osgeo._gdal' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/extensions
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/local/include/python3.7m -I. -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.7/extensions/gdal_wrap.o -I/usr/include
  extensions/gdal_wrap.cpp: In function 'OSRSpatialReferenceShadow* GDALDatasetShadow_GetSpatialRef(GDALDatasetShadow*)':
  extensions/gdal_wrap.cpp:4672:54: error: 'GDALGetSpatialRef' was not declared in this scope
       OGRSpatialReferenceH ref = GDALGetSpatialRef(self);
                                                        ^
  extensions/gdal_wrap.cpp: In function 'void GDALDatasetShadow_SetSpatialRef(GDALDatasetShadow*, OSRSpatialReferenceShadow*)':
  extensions/gdal_wrap.cpp:4681:57: error: 'GDALSetSpatialRef' was not declared in this scope
        GDALSetSpatialRef( self, (OGRSpatialReferenceH)srs );
...
...
  In file included from /usr/local/include/python3.7m/Python.h:147:0,
                   from extensions/gdal_wrap.cpp:173:
  /usr/local/include/python3.7m/abstract.h:489:17: note: declared here
   PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
                   ^~~~~~~~~~~~~~~~~~~~~
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for gdal
Running setup.py clean for gdal
...
...
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-hlldvrpz/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-record-fapa0jlw/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-hlldvrpz/gdal/

你的输出被修剪了 - 看起来你漏掉了实际的gcc错误,第一个“note”之前的行。 - valiano
该工具抱怨日志中有太多的代码!我已经修剪并添加了日志。如果需要更多,请告诉我,我会在这里的注释中添加它们。 - anzaan
谢谢@anzaan,好了:-) 我的直觉告诉我pip gdal与已安装的自定义gdal apk冲突。也许尝试显式安装所需的gdal版本,类似于:pip install 'gdal==2.4.0' --force-reinstall(因为`2.4.0是Alpine可用的最新版本)。 - valiano
成功了!pip install gdal==2.4.0。感谢@valiano。 - anzaan
太好了,成功了!那我会把它作为一个正式的答案发布。干杯! - valiano
2个回答

8

看起来存在GDAL版本冲突:

  • pip install gdal会拉取GDAL 3.0.0的源代码压缩包并尝试从源代码构建;
  • 安装的是2.4.0-r1版本的gdal-dev包,这确实是Alpine软件库中最新的版本;
  • GDAL 3.0.0无法使用2.4.0-r1版本的gdal-dev头文件进行构建。

作为解决方法,安装匹配版本2.4.0的GDAL模块可能会成功:

pip install 'gdal==2.4.0'


2

您没有完整的Python开发环境。

apk add --no-cache gcc g++ python python-dev py-pip mysql-dev linux-headers libffi-dev openssl-dev 

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