Skip to content

SIRF and Python

Edoardo Pasca edited this page Jan 12, 2018 · 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 

SuperBuild installation

After building and installing SIRF with the SuperBuild, two environment files for (bash and csh) are created. These files contain all the necessary information about the binary installation to avoid conflicts of versions of software.

Before using SIRF, these files should be sourced in a shell session. In particular, they contain the fields

  • $SIRF_PYTHON_EXECUTABLE which points to the python executable that was used during the build.
  • $PYTHON_DEST which points to the location of the python modules for SIRF

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