Skip to content

SIRF and Python

Kris Thielemans edited this page Apr 30, 2017 · 21 revisions

SIRF can be called from Python. This page documents some issues that you might encounter.

Version conflicts

If you have more than 1 Python version installed, you could encounter conflicts when installing or using SIRF. For instance, many people have both python2.7 and python3, or have different virtualenv's. You will have to create a separate SIRF build for every version of Python that you want to use. Obviously, you will also have to install Python packages for each. Using an environment such as Anaconda might help.

If you have conflicts during installation, or CMake picked up the wrong version, we recommend to first try to set the CMake variable PYTHON_EXECUTABLE (use an absolute path!). For instance,

    # find out where python3 sits
    which python3
    cmake -DPYTHON_EXECUTABLE=/usr/bin/python3

If that fails, set both PYTHON_LIBRARY and PYTHON_INCLUDE_DIR. On many systems python-config or python3-config can help.

Linux

As an example, you could have

$ python3-config --ldflags
-L/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu -L/usr/lib -lpython3.4m -lpthread -ldl  -lutil -lm  -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
$ python3-config --cflags
-I/usr/include/python3.4m -I/usr/include/python3.4m  -Wno-unused-result -g -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes

This tells you that appropriate settings are

PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so
PYTHON_INCLUDE_DIR=/usr/include/python3.4m

MacOS

When you want to use Python2, the following might work

cmake -DPYTHON_LIBRARY=$(python-config --prefix)/lib/libpython2.7.dylib -DPYTHON_INCLUDE_DIR=$(python-config --prefix)/include/python2.7 

Python packages

Using Anaconda

Try the following

conda update conda
conda update --all
conda install docopt
pip install sphinx_bootstrap_theme

Using pip

This might work. Use pip3 when using Python3. Add the --user option if you don't have administrator permissions.

pip install --upgrade pip setuptools wheel
pip install --only-binary=numpy,scipy,matplotlib numpy scipy matplotlib
pip install docopt