Skip to content

SIRF and Python

Richard Brown edited this page Mar 2, 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 should work:

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

If you prefer to use python3, you will need to find the relevant locations of your Python library and include directories. If you installed python3 with brew, the parent directory should be something like the one shown below:

/usr/local/Cellar/python3/<exact_version>/Frameworks/Python.framework/Versions/3.6

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

In the following a list of Python packages which are needed for SIRF to work

scipy 
matplotlib 
docopt  
h5py 
libxml2-python
psutil 
spyder 
TkInter
nose
coverage

On a debian based system you would issue

apt-get install python-scipy  python-docopt python-numpy python-h5py python-matplotlib python-libxml2 python-psutil spyder python-tk python-nose python-coverage

Using different python package managers

The current list of required python packages can be found above. In the next sections you can find an incomplete set of instruction for conda and pip.

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