Memo-migrated‎ > ‎

Python + VTK + Boost

posted Aug 15, 2013, 11:55 PM by Teng-Yok Lee   [ updated Jan 3, 2021, 12:23 AM ]
Recently I am working on making my one of my C/++ libraries to work with python. I also plan to use the VTK python binding so I can easily write plot figures via VTK. As the procedure is much much much more complicated than what I expected, here is my note about the procedure:

Step 1: Install Boost

DO not install Boost separately from the source. This is pretty weird, but because the b2/bjam in boost is not copied to the installed folder, I decide to use the same folder for both the installation and the source.

Step 2: Import the VTK python modules

If needed, the VTK should be built from the source with Python binding. My procedure is here. Then setup the following environment variable.
  • Add <VTK_install_prefix>/lib and <VTK_install_prefix>/site-packages/vtk to PYTHONPATH.
  • Add <VTK_install_prefix>/bin to PATH (for windows) or LD_LIBRARY_PATH (unix).

Step 3: Build the python binding for my library

I tried both Boost.Build and CMake. In my opinion, CMake is much much easier to user. Here is my procedure:
Python + Boost + CMake: Much easier thab Boost.Build

If you want to use Boost.Build, see the appendix.

Step 4: Test it on Windows

My current approach is using notepad++ with the plugin PyNpp. It allows me to run the tutorial without going to the command line shell.

UPDATED: Later I switch to PyDev in Eclipse because 1) Eclipse can be configured to use the hot keys of Visual Studio, and 2) PyDev can detect lots of errors in compilation time (e.g. undefined local variable and methods, misused of keywords, etc),

Appendix: Build the python binding for my library with

This procedure is too complicated and not recommended. I just list it here as a memo.

Configure boost and python

First, type bootstrap --with-python

Then it should output the following information

Building Boost.Build engine

Bootstrapping is done. To build, run:


To adjust configuration, edit 'project-config.jam'.
Further information:

    - Command line help:
    .\b2 --help

    - Getting started guide:

    - Boost.Build documentation:

2. Edit %HOMEDRIVE%%HOMEPATH%\user-config.jam by adding the following line:

using python : 2.7 : C:/python27 ;

3. Run the command below to build the 64-bit shared libraries for Visual Studio 2010 (PS. I usually build static libraries, but python extension is built as .dll).

b2 --toolset=msvc-10.0 architecture=x86 address-model=64 link=shared 

4. Install boost

b2 install --prefix=D:\boost

5. Go to your project (e.g. D:\boost_1_54_0\libs\python\example\tutorial), and type

D:\boost_1_54_0\b2.exe release -sBOOST_ROOT=D:\boost_1_54_0 --toolset=msvc-10.0 address-model=64 link=shared linkflags=/LIBPATH:D:\boost_1_54_0\stage\lib

Note that link=shared.

More detail about the usage of boost.python can be seen in my another post.