我正试图在我的M1 mac上安装geopandas,但我遇到了错误
我试图单独安装所有依赖项,但我遇到的问题是安装pyproj。
我使用brew安装PROJ安装了PROJ,这很好地实现了
当我尝试pip安装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
如有任何帮助,将不胜感激
目前,在M1 Mac上安装geopandas可以通过conda或pip+自制程序实现。
GeoPandas本身是用纯Python编写的,所以在任何架构上运行它都没有问题。然而,它取决于用其他语言(C、C++(编写的其他库,这些库需要专门针对M1芯片进行编译。虽然你可以自己编译它,但我不打算讨论这个选项,因为它对用户不友好。
所需库有三种可能的来源——pip轮子、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锻造厂目前拥有地球标准所需的所有包
安装M1版本的miniorge或mambaforge。它可以从这里下载-https://github.com/conda-forge/miniforge.
conda install -c conda-forge geopandas pygeos
注意:如果您安装x86(Intel(版本的conda,它将在Rosetta2下运行,并安装所有使用x86架构的软件包,这意味着一切都将在模拟下运行。尽量避免这种情况。
皮普和自制方式
Homebrew可以安装为M1编译的C库。Python包将找到并使用它们。
使用Python 3.9 环境
安装美观:
brew install geos
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/geos/lib/
pip install shapely
shapely需要DYLD_LIBRARY_PATH
才能找到GEOS安装。
安装fiona:
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.
相关https://github.com/pyproj4/pyproj/issues/1027
我遇到了同样的问题,我也尝试设置PROJ_DIR, PROJ_LIBDIR, PROJ_INCDIR
的环境值,但可能是设置值导致了错误,所以关闭了终端并重试,并能够正确安装
2023年3月,我在M1架构的maxOS Monterey上遇到了这个问题。不同的是,我使用Poetry来管理依赖关系。
我遵循了@martinflies流程,它也适用于Poetry。下面显示了Poetry的小语法变化。
诗歌与自制方式
Homebrew可以安装为M1编译的C库。Python包将找到并使用它们。
使用Python 3.9 环境
安装美观:
brew install geos
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/geos/lib/
poetry add shapely
shapely需要DYLD_LIBRARY_PATH来查找GEOS安装。
安装fiona:
brew install gdal
poetry add fiona
安装pyproj:
brew install proj
poetry add pyproj
安装用于加速的geopandas和pygeos:
poetry add pygeos
poetry add geopandas
使用pyproject.toml文件
brew install geos gdal proj
pyproject.toml(版本是*,如果以后使用,则允许使用最新的依赖版本(:
[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["Anon <anon@ymo.us>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
shapely = "*"
fiona = "*"
pyproj = "*"
pygeos = "*"
geopandas = "*"
[tool.poetry.group.dev.dependencies]
jupyter = "^1.0.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"