Skip to content

Instantly share code, notes, and snippets.

@jsoma
Last active September 8, 2022 13:37
Show Gist options
  • Save jsoma/df1dc2e8fcede356cfecce7b6d0aa70d to your computer and use it in GitHub Desktop.
Save jsoma/df1dc2e8fcede356cfecce7b6d0aa70d to your computer and use it in GitHub Desktop.
Installing cartopy inside of a pipenv virtual environment using GEOS/GDAL/PROJ from Homebrew

Install all of your "real" geo dependencies using homebrew

brew install proj
brew install geos
brew install gdal

Create your pipenv

pipenv --python 3.7

Install your packages

# Start off with a nice easy normal package install
pipenv install Cython

# We need to do this first so it finds the right shapely, I think?
# https://github.com/SciTools/cartopy/issues/1177
# And we need to do no binary, or you get Bus error: 10
# https://github.com/SciTools/cartopy/issues/1274
PIP_NO_BINARY=shapely pipenv install shapely

# https://stackoverflow.com/questions/31107638/python-gdal-installation-by-pip-fails
# Plus gdalinfo magic - the version of gdal Python lib needs to match the GDAL version
pipenv install gdal==`gdalinfo --version | sed s/,// | awk '{print $2}'`

# Need to use USE_OMP=0 below because https://github.com/storpipfugl/pykdtree says:
# "By default pykdtree is built with OpenMP enabled queries using libgomp except on 
# OSX systems using the clang compiler (conda environments use a separate compiler)."
USE_OMP=0 pipenv install pykdtree

# https://scitools.org.uk/cartopy/docs/latest/installing.html#optional-dependencies
pipenv install matplotlib Pillow pyepsg scipy OWSLib fiona pyproj

# Don't want to install a bianry
# https://github.com/pypa/pipenv/issues/1430
# Need to accept deprecated proj using CFLAGS
# https://github.com/OSGeo/PROJ/issues/836
CFLAGS='-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H' PIP_NO_BINARY=cartopy pipenv install cartopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment