Python Bindings CMake instructions - neutronimaging/imagingsuite GitHub Wiki

Return to python binding manual main page

The python bindings are implemented using the template library pybind11. This is a convenient library for binding C++ code to python.

Prerequisites

Compiler

You need a C++ compiler that supports at least C++11 to compile the python bindings.

Python interpreter

The python bindings are compiled to work with a specific python version only, it doesn't matter if you use 2.7 or 3.x. The unit tests are however made for python 3.x. This means that you need to know which python interpreter is uses during compilation, otherwise it will not work to import the binding library. You can determine which python interpreter is used by calling

$ which python

In order to make the bindings work you need to install support for pybind11

$ pip install pybind11

CMake

The compilation of the python bindings is done using CMake. You need to install CMake version >3.11 for the compilation to work. The CMake files is configured to download the required pybind11 components while compiling.

KIPL core library

The python bindings depend on features in the KIPL core library. This needs to be compiled and linked with the binding library. The KIPL library also has dependencies that have to be available to use the bindings. Building kipl is best done using the build scripts in imagingsuite/build

Building

Build the library using the following commands from the '/imagingsuite/core/algorithms/' folder:

$ mkdir -p build
$ cd build
$ cmake ..
$ cmake --build .

Using a different python interpreter

If you want to specify a different python version please replace the

$ cmake ..

with

$ cmake -DPYTHON_EXECUTABLE:FILEPATH=<path-to-python-executable> ..

Dependencies

Run the script 'copydeps.sh' to copy needed libs to the build folders. The script also copies test scripts to the folder.

Testing the bindings

We have implemented unit tests to verify that the python bindings work. These tests are mainly to check bindings and not numerical performance. Such tests are done in C++ using QTest.

After building the libraries, you can run the tests using

$ ctest

Known problems

  1. The shared object files on MacOS have the extension .dylib. This is unfortunately not understood by the python environment that only accepts .so libs. Solution: You have to stand in the folder of the library with bindings to import the library. This is a problem also when you try to run the unit tests.
⚠️ **GitHub.com Fallback** ⚠️