Categories
Web Map

Build your self-host world map – Install mapnik & python-mapnik on MacOS

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:

%brew update

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.

11 replies on “Build your self-host world map – Install mapnik & python-mapnik on MacOS”

doesn’t bulid on macOS Catalina 10.15.6

/usr/local/include/mapnik/cairo/cairo_context.hpp:43:10: fatal error: ‘cairo.h’ file not found

after following your guide I get an import error

ImportError: dlopen([…]/python-mapnik/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

do you have any idea what causes this?

Hi Mark,

Which step did you encounter the issue? Can you please confirm you have used the right python version “python3” (my computer version is python3.9 installed by brew) to execute the install script?

Hey,

I already resolved the issue and indeed there was a problem with the system python version and boost. Installing python via brew @3.9 fixed the issue.

Hello Ukalpa,
thank you very much for your guide.
While running % python3 setup.py test i got 5 failures and 11 errors:
ERROR: python_tests.projection_test.test_wgs84_inverse_forward
ERROR: python_tests.projection_test.test_proj_antimeridian_bbox
ERROR: python_tests.raster_symbolizer_test.test_dataraster_coloring
ERROR: python_tests.raster_symbolizer_test.test_dataraster_query_point
ERROR: python_tests.raster_symbolizer_test.test_load_save_map
ERROR: python_tests.raster_symbolizer_test.test_raster_warping
ERROR: python_tests.raster_symbolizer_test.test_raster_warping_does_not_overclip_source
ERROR: python_tests.render_test.test_render_points
ERROR: python_tests.reprojection_test.test_visual_zoom_all_rendering3
ERROR: python_tests.reprojection_test.test_visual_zoom_all_rendering4
ERROR: python_tests.save_map_test.test_compare_map
FAIL: python_tests.image_filters_test.test_style_level_image_filter
FAIL: python_tests.load_map_test.test_good_files
FAIL: python_tests.projection_test.test_normalizing_definition
FAIL: python_tests.render_test.test_render_with_scale_factor
FAIL: python_tests.webp_encoding_test.test_transparency_levels

Hi Rikardo,
1. Is your computer’s os MacOS and Version?
2. Have you strictly followed the steps I provided?
3. Which command did you encounter the above issue?

Hey ukalpa,
thanks for the quick feedback.
1. macOS Big Sur 11.2.3
2. I followed all your steps.
3. I tried to run the ‘python3 setup.py test’ and got these errors.

However, I think that mapnik + python-mapnik already works.
After I followed your guide i started following https://github.com/mapnik/mapnik/wiki/GettingStartedInPython
After following the other guide i was already able to create a python script according to the tutorial and render a world.png. so it should work now, even if this test nothing works πŸ˜€
Thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *