在 mac m1 上用 python 安装 geopandas 时出错

jay*_*eue 5 pip geopandas pyproj pyproject.toml

我正在尝试在我的 M1 mac 上安装 geopandas,但遇到错误

\n

我尝试单独 pip 安装所有依赖项,但我遇到问题的是 pyproj 的安装。

\n

我使用brew install proj安装了PROJ,效果很好

\n

当我尝试 pip install pyproj 时,出现以下错误

\n
Building wheels for collected packages: pyproj  \n\nBuilding wheel for pyproj (pyproject.toml) ... error\n  error: subprocess-exited-with-error\n  \n  \xc3\x97 Building wheel for pyproj (pyproject.toml) did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [12 lines of output]\n      PROJ_DIR is set, using existing PROJ installation..\n      \n      running bdist_wheel\n      running build\n      running build_py\n      running build_ext\n      building 'pyproj._geod' extension\n      pyproj/_geod.c:704:10: fatal error: 'geodesic.h' file not found\n      #include "geodesic.h"\n               ^~~~~~~~~~~~\n      1 error generated.\n      error: command '/usr/bin/clang' failed with exit code 1\n      [end of output]\n  \n  note: This error originates from a subprocess, and is likely not a problem with pip.\n  ERROR: Failed building wheel for pyproj\nFailed to build pyproj\nERROR: Could not build wheels for pyproj, which is required to install pyproject.toml-based projects\n
Run Code Online (Sandbox Code Playgroud)\n

任何帮助将非常感激

\n

mar*_*eis 17

目前,在 M1 mac 上安装 geopandas 可以通过 conda 或 pip+homebrew 来实现。

GeoPandas 本身是用纯 Python 编写的,因此在任何架构上运行都没有问题。然而,它依赖于用其他语言(C、C++)编写的其他库,需要专门为M1芯片编译。虽然您可以自己编译它,但我不会介绍此选项,因为它对用户不友好。

所需库有三种可能的来源 - pipwheels、conda-forge 和 Homebrew。

当Python包需要C依赖时,它可以使用针对每个系统和芯片架构编译的依赖来创建轮子。例如,请参见 pygeos - https://pypi.org/project/pygeos/#files。你需要的是*macosx_11_0_arm64.whl . 如果您的软件包没有提供它,您必须找到除 之外的另一种安装方式pip。由于 GeoPandas 需要 shapely 和 fiona(以及其他),而它们没有这些轮子,因此您应该寻找其他地方 - 无论是 conda-forge 还是 Homebrew。以下是截至今天测试的两个选项。

conda和conda-forge方式(推荐)

Conda-forge 目前拥有 geopandas 需要的所有包

安装 M1 版本的 miniforge 或 mambaforge。可以从这里下载 - https://github.com/conda-forge/miniforge

conda install -c conda-forge geopandas pygeos
Run Code Online (Sandbox Code Playgroud)

注意:如果您安装 x86(Intel)版本的 conda,它将在 Rosetta2 下运行并使用 x86 架构安装所有软件包,这意味着所有内容都将在模拟下运行。尽量避免这种情况。

Pip 和 Homebrew 方式

Homebrew 可以安装为 M1 编译的 C 库。Python 包将找到并使用它们。

使用Python 3.9的环境

安装整齐:

brew install geos
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/geos/lib/
pip install shapely
Run Code Online (Sandbox Code Playgroud)

DYLD_LIBRARY_PATHShapely 需要找到 GEOS 安装。

安装菲奥娜:

brew install gdal
pip install fiona
Run Code Online (Sandbox Code Playgroud)

安装pyproj:

brew install proj
pip install pyproj
Run Code Online (Sandbox Code Playgroud)

安装 geopandas 和 pygeos 以提高速度:

brew install gdal
pip install fiona
Run Code Online (Sandbox Code Playgroud)

请注意,这是我自己在https://github.com/geopandas/geopandas/issues/1816#issuecomment-1003093329中给出的解释的复制粘贴。