Error installing geopandas in python on mac m1
Asked Answered
C

3

5

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

Cadge answered 16/2, 2022 at 7:11 Comment(1)
File a bug report, I think that's easiest. For a question here, extract a minimal reproducible example. In short, you are missing a library's header file.Verine
U
17

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 and conda-forge way (recommended)

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.

Pip and Homebrew way

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.

Unglue answered 16/2, 2022 at 9:24 Comment(2)
thanks. the pip approach is the process I followed. Where I'm getting stuck is on pyproj. I'm able to "brew install proj" successfully but I get an error on the "pip install pyproj" step. this is the traceback I pasted in my original question. any ideas on how I can get around it?Cadge
PROJ seems to be incorrectly installed for some reason. Check if PROJ_DIR actually points to PROJ.Unglue
H
1

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

Harlequinade answered 14/6, 2022 at 13:42 Comment(0)
P
0

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.

Poetry and Homebrew way

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/
poetry add shapely

DYLD_LIBRARY_PATH is needed for shapely to find GEOS installation.

Install fiona:
brew install gdal
poetry add fiona
Install pyproj:
brew install proj
poetry add pyproj
Install geopandas and pygeos for speedups:
poetry add pygeos
poetry add geopandas

Using pyproject.toml file

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"
Peccavi answered 23/3, 2023 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.