Reputation: 415
I'm trying to install geopandas on my M1 mac and I'm running into errors
I tried to pip install all the dependencies individually but where I'm tripping up is in the install of pyproj.
I installed PROJ using brew install proj and that worked fine
When I try to pip install pyproj, I get the follow error
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
Any help would be much appreciated
Upvotes: 5
Views: 6481
Reputation: 708
I encountered this issue on maxOS Monterey with M1 architecture in March 2023. The difference is that I use Poetry for dependency management.
I followed @martinflies process and it also worked for Poetry. Shown below with minor syntax changes for Poetry.
Homebrew can install C libraries compiled for M1. Python packages will find and use them.
Using an environment with Python 3.9
brew install geos
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/geos/lib/
poetry add shapely
DYLD_LIBRARY_PATH is needed for shapely to find GEOS installation.
brew install gdal
poetry add fiona
brew install proj
poetry add pyproj
poetry add pygeos
poetry add geopandas
brew install geos gdal proj
pyproject.toml (versions are * to allow newest dependency versions if you use this at a later date) :
[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["Anon <[email protected]>"]
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"
Upvotes: 0
Reputation: 499
Related https://github.com/pyproj4/pyproj/issues/1027
I was stuck with the same problem, I also tried setting the environment values for PROJ_DIR, PROJ_LIBDIR, PROJ_INCDIR
but perhaps setting the values is causing the error, so closed the terminal and tried again and was able to install correctly
Upvotes: 1
Reputation: 7804
At the moment, installing geopandas on M1 macs can be achieved via conda or pip+homebrew.
GeoPandas itself is written in pure Python, so there is no issue running that on any architecture. However, it depends on other libraries that are written in other languages (C, C++) that need to be compiled specifically for M1 chips. While you could compile it yourself, I am not going to cover this option as it is not user friendly.
There are three possible sources of required libraries - pip wheels, conda-forge, and Homebrew.
When a Python package requires C dependency, it can create wheels with the dependency compiled for each system and chip architecture. See for example pygeos - https://pypi.org/project/pygeos/#files. What you need is *macosx_11_0_arm64.whl
. If your package doesn't offer it, you have to find another way of installing than pip
. Since GeoPandas requires shapely and fiona (among others) that do not have these wheels, you should look elsewhere - either on conda-forge or Homebrew. Below are both options tested as of today.
Conda-forge currently has all packages geopandas needs
Install M1 version of miniforge or mambaforge. It can be downloaded from here - https://github.com/conda-forge/miniforge.
conda install -c conda-forge geopandas pygeos
Note: if you install x86 (Intel) version of conda, it will run under Rosetta2 and install all packages using x86 architecture, meaning that everything will run under emulation. Try to avoid that.
Homebrew can install C libraries compiled for M1. Python packages will find and use them.
Using an environment with Python 3.9
Install shapely:
brew install geos
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/geos/lib/
pip install shapely
DYLD_LIBRARY_PATH
is needed for shapely to find GEOS installation.
Install fiona:
brew install gdal
pip install fiona
Install pyproj:
brew install proj
pip install pyproj
Install geopandas and pygeos for speedups:
pip install pygeos
pip install geopandas
Note that this is a copy&paste of my own explanation given in https://github.com/geopandas/geopandas/issues/1816#issuecomment-1003093329.
Upvotes: 17