高山编译中的Gdal安装失败-“错误:命令'gcc'失败,退出状态为1”

anz*_*aan 3 gcc gdal docker alpine-linux

我正在尝试在Alpine docker env中安装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
Run Code Online (Sandbox Code Playgroud)

然后,我运行命令“ "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/
Run Code Online (Sandbox Code Playgroud)

val*_*ano 5

似乎存在GDAL版本冲突:

  • pip install gdal 提取GDAL 3.0.0的源代码压缩包,并尝试从源代码构建它;
  • gdal-dev正在安装2.4.0-r1 软件包,这确实是Alpine信息库中提供的最新软件包;
  • GDAL 3.0.0不会针对2.4.0-r1 gdal-dev标头构建。

解决方法是,成功安装匹配版本2.4.0的GDAL模块:

pip install 'gdal==2.4.0'