1

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

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

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

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

Building wheels for collected packages: pyproj  

Building wheel for pyproj (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for pyproj (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      PROJ_DIR is set, using existing PROJ installation..
      
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building 'pyproj._geod' extension
      pyproj/_geod.c:704:10: fatal error: 'geodesic.h' file not found
      #include "geodesic.h"
               ^~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyproj
Failed to build pyproj
ERROR: Could not build wheels for pyproj, which is required to install pyproject.toml-based projects

任何帮助将非常感激

4

1 回答 1

2

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

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

所需库的三种可能来源 - pip Wheels、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

注意:如果您安装 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

DYLD_LIBRARY_PATH需要匀称地找到 GEOS 安装。

安装菲奥娜:

brew install gdal
pip install fiona

安装 pyproj:

brew install proj
pip install pyproj

安装 geopandas 和 pygeos 以加快速度:

pip install pygeos
pip install geopandas

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

于 2022-02-16T09:24:22.707 回答