如何在Amazon Linux 2 arm64实例上成功安装geopandas?
问题:Arm64架构Amazon Linux 2上安装Geopandas失败
在arm64架构的Amazon Linux 2 EC2实例中执行pip install geopandas时安装失败,核心原因是Geopandas依赖的Fiona需要GDAL,但系统中未找到gdal-config工具,导致无法获取GDAL API版本信息。
安装报错信息:
pip install geopandas Collecting geopandas Downloading geopandas-0.10.2-py2.py3-none-any.whl.metadata (935 bytes) Collecting pandas>=0.25.0 (from geopandas) Downloading pandas-1.3.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (12 kB) Collecting shapely>=1.6 (from geopandas) Downloading shapely-2.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (7.0 kB) Collecting fiona>=1.8 (from geopandas) Downloading fiona-1.9.5.tar.gz (409 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 409.3/409.3 kB 9.0 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [4 lines of output] /tmp/pip-install-_c7449ly/fiona_e22cd934b7ad4d2e824ee7831b133267/setup.py:86: DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead logging.warn("Failed to get options via gdal-config: %s", str(e)) WARNING:root:Failed to get options via gdal-config: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config' CRITICAL:root:A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
系统版本信息:
cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" SUPPORT_END="2025-06-30"
疑问:是否有人成功在该环境下安装过Geopandas?尝试安装GDAL时依赖安装失败,是否必须从源码编译?
解决方案
通过源码编译PROJ和GDAL来满足Fiona的依赖需求,执行以下命令:
dnf -y install wget gcc-c++ cpp sqlite-devel libtiff cmake python3-pip \ python-devel openssl-devel tcl libtiff-devel libcurl-devel \ swig libpng-devel libjpeg-turbo-devel expat-devel \ && dnf clean all \ && pip3 install setuptools numpy \ && wget https://download.osgeo.org/proj/proj-9.3.1.tar.gz \ && tar zxvf proj-9.3.1.tar.gz \ && cd proj-9.3.1/ \ && mkdir build \ && cd build \ && cmake .. \ && cmake --build . --parallel $(nproc) \ && cmake --install . --prefix /usr \ && cd ~ \ && wget https://github.com/OSGeo/gdal/releases/download/v3.8.3/gdal-3.8.3.tar.gz \ && tar xvzf gdal-3.8.3.tar.gz \ && cd gdal-3.8.3/ \ && mkdir build \ && cd build \ && cmake -DGDAL_BUILD_OPTIONAL_DRIVERS=OFF -DOGR_BUILD_OPTIONAL_DRIVERS=OFF .. \ && cmake --build . --parallel $(nproc) \ && cmake --install . --prefix /usr
编译完成后,再次执行pip install geopandas即可完成安装。
内容的提问来源于stack exchange,提问作者Jordan Laser
相关产品推荐
相关产品推荐

