Mapnik is a mapping toolkit for developing mapping applications. it can generate map tiles with specific requirements based on the data in PostGIS generated by OSM. This article introduces how to install it and the python library “python-mapnik” for Python3 on Mac OS.
First, make sure you have installed homebrew on your Macbook. And it is updated:
Then, install mapnik:
%brew install mapnik
After installed, Execute “brew info mapnik” to check the installed details, you can see the version 3.1.0 has been installed successfully as below:
Now, let us start to install “python-mapnik”:
First, clone the “python-mapnik” source code to the local directory and switch its version to “v3.0.x”, the reason for switching the version is because the master branch is not compatible with the previous installed mapnik’s version.
%git clone https://github.com/mapnik/python-mapnik.git %cd python-mapnik %git checkout v3.0.x
You may encounter the issue: “library not found boost_python” when installing python-mapnik, to solve it, we need to install “boost-python3” firstly.
%brew install boost-python3
After installed “boost-python3”, execute the command
%ls -l /usr/local/lib/libboost_python*
to check the installed version, you can see libboost_python39 has been installed on my computer.
Now, start to install the “python-mapnik” library:
// "39" should be the install version as same as above %export BOOST_PYTHON_LIB=boost_python39 %python3 setup.py install
After the installation is finished, you should see the below result.
You can execute the following commands to test if it is installed successfully:
%git submodule update —init %python3 setup.py test
Now, we have installed “mapnik” and “python-mapnik” successfully in the system, you can execute a simple python code to get where the library is stored as below, please notice that you might need to restart your terminal instance for Python to identify the library.
Welcome to comment if you have any questions.