Skip to content

Instantly share code, notes, and snippets.

@snickell
Last active October 8, 2021 17:04
Show Gist options
  • Save snickell/ee8f3d96f11f457c30ef5416a12d625e to your computer and use it in GitHub Desktop.
Save snickell/ee8f3d96f11f457c30ef5416a12d625e to your computer and use it in GitHub Desktop.
Script for installing python-mapnik on MacOS Catalina with Homebrew
#!/bin/bash
# note: boost needs to be >= 1.73, make sure boost@1.73 is linked too
brew install boost boost-python3 sqlite gdal cairo python@3.8
brew upgrade boost boost-python3 sqlite gdal cairo python@3.8
brew link boost
# We're build a custom mapnik 4, uninstall the stale 3.x version in homebrew:
brew uninstall mapnik
mkdir build-python-mapnik
cd build-python-mapnik
# Build Mapnik from master
git clone https://github.com/mapnik/mapnik
cd mapnik
git submodule update --init
set -e
# be explicit: python3 will result in sconstruct build failure
PYTHON=python2 ./configure SQLITE_INCLUDES=/usr/local/opt/sqlite3/include
JOBS=8 make
make install
set +e
cd ..
git clone https://github.com/mapnik/python-mapnik
cd python-mapnik
set -e
BOOST_PYTHON_LIB=boost_python38 python3 setup.py install
#!/bin/bash
# note: boost needs to be >= 1.73, make sure boost@1.73 is linked too
brew install boost boost-python3 sqlite gdal cairo python@3.8
brew upgrade boost boost-python3 sqlite gdal cairo python@3.8
brew link boost
# We're build a custom mapnik 4, uninstall the stale 3.x version in homebrew:
brew uninstall mapnik
mkdir build-python-mapnik
cd build-python-mapnik
# Build Mapnik from master
git clone https://github.com/mapnik/mapnik
cd mapnik
git submodule update --init
set -e
# be explicit: python3 will result in sconstruct build failure
PYTHON=python2 ./configure SQLITE_INCLUDES=/usr/local/opt/sqlite3/include
JOBS=8 make
make install
set +e
cd ..
git clone https://github.com/mapnik/python-mapnik
cd python-mapnik
set -e
BOOST_PYTHON_LIB=boost_python38 python3 setup.py install
cd ../..
python3 -c "import mapnik ; print(dir(mapnik))"
@flocker
Copy link

flocker commented Oct 27, 2020

Updated your script for MacOs 10.15.7; python 3.9 is required for boost-python3

#!/bin/bash

# note: boost needs to be >= 1.73, make sure boost@1.73 is linked too

brew install boost boost-python3 sqlite gdal cairo python@3.9
brew upgrade boost boost-python3 sqlite gdal cairo python@3.9
brew link boost

# We're build a custom mapnik 4, uninstall the stale 3.x version in homebrew:
brew uninstall mapnik

mkdir build-python-mapnik
cd build-python-mapnik

# Build Mapnik from master
git clone https://github.com/mapnik/mapnik
cd mapnik
git submodule update --init
set -e
# be explicit: python3 will result in sconstruct build failure
PYTHON=python2 ./configure SQLITE_INCLUDES=/usr/local/opt/sqlite3/include

JOBS=8 make
make install
set +e
cd ..

git clone https://github.com/mapnik/python-mapnik
cd python-mapnik
set -e
BOOST_PYTHON_LIB=boost_python39 /usr/local/Cellar/python@3.9/3.9.0/bin/python3 setup.py install

cd ../..

/usr/local/Cellar/python@3.9/3.9.0/bin/python3 -c "import mapnik ; print(dir(mapnik))"

@chrisdunley
Copy link

I found that as is the build didn't pick up some the options - GDAL and PROJ. I fixed this by adding to the configure line as follows:

PYTHON=python2 ./configure SQLITE_INCLUDES=/usr/local/opt/sqlite3/include GDAL_CONFIG=/usr/local/opt/gdal/bin/gdal-config PROJ_LIBS=/usr/local/lib PROJ_INCLUDES=/usr/local/include CUSTOM_DEFINES='-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1'

The last one allows use of newer versions of PROJ than PROJ 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment