Last active
October 8, 2021 17:04
-
-
Save snickell/ee8f3d96f11f457c30ef5416a12d625e to your computer and use it in GitHub Desktop.
Script for installing python-mapnik on MacOS Catalina with Homebrew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# note: boost needs to be >= 1.73, make sure [email protected] is linked too | |
brew install boost boost-python3 sqlite gdal cairo [email protected] | |
brew upgrade boost boost-python3 sqlite gdal cairo [email protected] | |
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 [email protected] is linked too | |
brew install boost boost-python3 sqlite gdal cairo [email protected] | |
brew upgrade boost boost-python3 sqlite gdal cairo [email protected] | |
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))" |
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 [email protected] is linked too
brew install boost boost-python3 sqlite gdal cairo [email protected]
brew upgrade boost boost-python3 sqlite gdal cairo [email protected]
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/[email protected]/3.9.0/bin/python3 setup.py install
cd ../..
/usr/local/Cellar/[email protected]/3.9.0/bin/python3 -c "import mapnik ; print(dir(mapnik))"
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
Thanks for your script. I'm on catalina. boost_python38 was installed to /usr/local/lib/libboost_python39
When i try to install python-mapnik got this error (maybe because of libboost_python39):
_File "/usr/local/lib/python3.8/site-packages/mapnik-4.0.0-py3.8-macosx-10.15-x86_64.egg/mapnik/init.py", line 74, in
from ._mapnik import *
ImportError: dlopen(/usr/local/lib/python3.8/site-packages/mapnik-4.0.0-py3.8-macosx-10.15-x86_64.egg/mapnik/_mapnik.cpython-38-darwin.so, 2): Symbol not found: PyCMethod_New
Referenced from: /usr/local/opt/boost-python3/lib/libboost_python39.dylib
Expected in: flat namespace
in /usr/local/opt/boost-python3/lib/libboost_python39.dylib