Building from source#

Choose your operating system for more information, in particular on alternative ways of installation or compilation from source:

You need a Python installation with the modules numpy and matplotlib. There are minimalistic installers and pre-packaged distributions. We recommend Anaconda 64bit but WinPython will to the job too.

You also need a Linux-like command shell along with a gcc compiler. Although there might be different solutions (Cygwin, Git Bash, MinGW/MSYS), we only support the MSYS2 (Minimal System 2) hosted at http://www.msys2.org. As computers and modern Windows (>=7) are 64bit we only test this. Avoid installing into strange Windows folders, e.g., c:ProgramDatamys64 is fine.

After installing MSYS, start the console once so it builds your personal home directory where you find a .bashrc file, e.g. in

c:\ProgramData\mys64\home\YOUR_USERNAME

Edit .bashrc so that the Anaconda or WinPython installation path is added to your default PATH.

e.g.:

export ANACONDA=/c/ProgramData/Anaconda3
export PATH=$PATH:$ANACONDA

This is necessary since gimli needs to know valid python installation and version. Ideally the following one-liner will suffice to compile pyGIMLi in the current directory.

Note: The script will automatically take care of requirements and updates of MSYS2. And also needs to modify/patch some of the llvm system files.

curl -Ls install.pygimli.org | bash

This script accepts a few more options. For help see

curl -Ls install.pygimli.org | bash -s help

If everything runs fine, including some tests, the script will tell you some additional PATH and PYTHONPATH settings for your .bashrc to use pygimli inside the console or any IDE like Spyder (coming along with WinPython).

If something goes wrong, please take a look on the error message.

You can alse try the following instructions for manual installation.

Make sure to have an updated msys2 environment. Run at least:

pacman -Su
pacman -Sy

to update your local package databases. See https://www.msys2.org/ for further instructions.

To get a complete working toolchain you need some packages installed.

pacman -S make tar git subversion mercurial unzip wget patch
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-gcc-fortran
pacman -S mingw-w64-x86_64-openblas mingw-w64-x86_64-suitesparse
pacman -S mingw-w64-x86_64-doxygen mingw-w64-x86_64-cppunit
pacman -S mingw-w64-x86_64-llvm mingw-w64-x86_64-clang

The rest of the installation is like the linux way with some small differences.

Prepare the directory structure as described above:

The build is performed via cmake. While calling cmake MSYS users should tell using the Unix makefile generator to find the correct gcc versions:

cmake ../gimli -G 'Unix Makefiles'

If cmake complains about missing python stuff, make sure the Python interpreter is in your execution path.

Problems with cmake configuration

If cmake can’t install pygccxml or pyplusplus then you can provide those packages using pip from the anaconda distribution. First make sure the needed scripts are in your path.

export PATH=$PATH:$ANACONDA/Scripts

Then you can install those both packages in your user space

pip install pygccxml --user
pip install pyplusplus --user

If cmake complains about misssig numpy, python can’t probably import numpy, which you can test:

python -c 'import numpy'

Probably anaconda additional needs another path setting, don’t ask me why

export PATH=$PATH:$ANACONDA/Library/bin

Now python should be able to find numpy and cmake will work as supposed and you can continue the build process.

To build the library, just run

make -j2

You might add the option -jN to use a number of N CPUs in parallel. To build pygimli, run

make pygimli J=2

You might add J=N to use a number of N CPUs in parallel. Building pygimli takes some time and you can grab a coffee (or two). If it finishes without errors you just need to set the environment: (note that pygimli is still built in-place, in pygimli/core)

export PYTHONPATH=$PYTHONPATH:$HOME/src/gimli/gimli/python
export PATH=$PATH:$HOME/src/gimli/build/lib
export PATH=$PATH:$HOME/src/gimli/build/bin

Compiled binaries will be written to build/bin.

You can test the pygimli build with:

python -c 'import pygimli as pg; print(pg.version())'

The current working solution is based on this discussion on GitHub. Many thanks to Robin Thibaut!

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# Install dependencies via brew
brew install cmake
brew install wget
brew install mercurial

# Install Miniforge
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh

conda create -n pygimli_env python
conda activate pygimli_env
conda install -c conda-forge boost numpy scipy matplotlib openblas suitesparse

# Clone the pygimli repository
git clone https://github.com/gimli-org/gimli.git source
mkdir build
cd build

PYTHON_EXEC=$(which python3)
PYTHON_INC=$(python3 -c 'import sysconfig; print(sysconfig.get_path("include"))')
PYTHON_LIB=$(python3-config --configdir)

export CPLUS_INCLUDE_PATH=$PYTHON_INC

cmake -DPYTHON_EXECUTABLE=$PYTHON_EXEC -DPYTHON_LIBRARY=$PYTHON_LIB -DPYTHON_INCLUDE_DIR=$PYTHON_INC ../source
make -j 8
make pygimli J=8

If you encounter problems, you may have to specify some paths manually, e.g.:

cmake -DPYTHON_EXECUTABLE=$PYTHON_EXEC -DPYTHON_LIBRARY=$PYTHON_LIB
      -DPYTHON_INCLUDE_DIR=$PYTHON_INC \
      -DUMFPACK_LIBRARIES=~/minforge3/base/lib/libumfpack.dylib \
      -DUMFPACK_INCLUDES=~/minforge3/base/include \
      -DCHOLMOD_LIBRARIES=~/minforge3/base/lib/libcholmod.dylib \
      -DCHOLMOD_INCLUDE_DIRS=~/minforge3/base/include \
      -DBLAS_openblas_LIBRARY=~/minforge3/base/lib/libopenblas.dylib \
      -DOpenBLAS_INCLUDE_DIR=~/minforge3/base/include \
      -DBoost_PYTHON_LIBRARY=~/minforge3/base/lib/libboost_python310.dylib \
      ../source

If you don’t want to use the conda environment we encourage the use of a virtual python environment. Assuming you have a proper build toolchain and the required libraries (see Installation on Ubuntu below) installed.

We recommend an out of source build:

There is no more need to change the PATH` or LD_LIBRARY_PATH`. In fact, check to remove any prior changes to these environment variables from older installations.

export PYTHONPATH=$PYTHONPATH:$(pwd)/gimli
python -c 'import pygimli as pg; pg.version()'

All following building procedures are outdated and may not work without tweaking

If you are not using Anaconda, you can build pyGIMLi from source in the current directory via:

curl -Ls install.pygimli.org | bash

This script accepts a few more options. For help see:

curl -Ls install.pygimli.org | bash -s help

If something goes wrong please take a look at the error message. In most cases there are missing or outdated packages. Please have a look at the prerequisites tab or in the following Ubuntu section.

If the installation fails you can try the following instructions for manual installation.

Last try on Ubuntu 22.04.03 (23-11-14)

sudo apt-get install build-essential g++ subversion git cmake \
             python3-dev python3-matplotlib python3-numpy python3-pyqt5 \
             python3-scipy libboost-all-dev libedit-dev \
             libsuitesparse-dev libopenblas-openmp-dev libumfpack5 \
             libcppunit-dev clang

mkdir -p ~/src/gimli
cd ~/src/gimli
git clone https://github.com/gimli-org/gimli.git

mkdir -p build
cd build
cmake ../gimli
make -j 4 gimli
make pygimli J=4

To use the gimli installation you need to set some environment variables (this example assumes that the src directory resides in your home directory):

GIMLI_INSTALLATION=$HOME/src/gimli
export PYTHONPATH=$PYTHONPATH:$GIMLI_INSTALLATION/gimli
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GIMLI_INSTALLATION/build/lib
export PATH=$PATH:$GIMLI_INSTALLATION/build/bin

You can do a quick test of the pygimli build and installation with:

python -c 'import pygimli as pg; print(pg.__version__)'

(Probably outdated.)

Tested on Debian 12 (Bookworm).

In order to build pygimli (and gimli) Python 3, install the required packages:

sudo apt-get install wget subversion git cmake mercurial g++ \
    libboost-all-dev libblas-dev liblapack-dev libopenblas-dev \
    libsuitesparse-dev libedit-dev python3-dev \
    python3-numpy python3-matplotlib \
    python3-setuptools

Create a directory for your installation, e.g., $HOME/src/gimli

mkdir -p ~/src/gimli
cd ~/src/gimli

Checkout the current sources for libgimli:

git clone https://github.com/gimli-org/gimli.git

We use cmake for compilation. We recommend using a build directory parallel to the gimli (trunk) path:

mkdir -p build

The main directory structure should looks like this:

gimli/gimli
gimli/build

Change to the build path

cd build

If you want to compile for Python 3.8, alternatively use:

cmake ../gimli -DPYVERSION=3.8

If the output complains about missing dependencies, install these and repeat the the last step. To build the library just run make.

make

To speed up the build process using more CPUs, use the -j flag, e.g.:

make -j 8

The libraries will be installed in build/lib and some test applications are installed in build/bin. If you want to build the Python bindings, call:

make pygimli

You might add J=8 (make pygimli J=8) for using 8 jobs in parallel to speed up the build (adapt this to the number of real cores of the computer). The library _pygimli_.so library will be copied into the source path ../gimli/pygimli in the subdirectory core.

To use the gimli installation you need to set some environment variables (this example assumes that the src directory resides in your home directory):

GIMLI_INSTALLATION=$HOME/src/gimli
export PYTHONPATH=$PYTHONPATH:$GIMLI_INSTALLATION/gimli
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GIMLI_INSTALLATION/build/lib
export PATH=$PATH:$GIMLI_INSTALLATION/build/bin

If you want to use the C++ command line applications, call

make apps

Compiled binaries will be written to build/bin.

You can do a quick test of the pygimli build and installation with:

python -c 'import pygimli as pg; print(pg.__version__)'

You can test your gimli build with:

make check

Note that the test will be very silent if you don’t have cppunit installed.

If you install pytest with

sudo apt-get install python-pytest python3-pytest

then you can run the internal test suite with

python -c "import pygimli; pygimli.test()"

If you want to use a Docker container to build (and possibly use) pyGIMLi, you can use the Dockerfile found in the scripts/ subdirectory named Dockerfile_DebianBookworm. Please refer to the file for further instructions.

If you experience runtime problems on starting pygimli like:

ImportError: /usr/lib/libboost_python.so: undefined symbol: PyClass_Type

It may happen that CMake estimates the wrong libboost_python version by choosing py2 version instead of py3. You can force cmake to select the correct version with:

cmake ../gimli -DBoost_PYTHON_LIBRARY=/usr/lib64/libboost_python3.so

castXML (CastXML/CastXML) is needed to generate the code for the python bindings. Some systems provide castxml binary so the build system should detect it if installed. As fallback solution the build system tries to install castxml binaries or try to compile there own if the binaries don’t work. You can enforce the local binary installation with:

cmake ../../src/castXML/ -DCASTXML_LOCAL=1
make

or the local binary compilation with:

cmake ../../src/castXML/ -DCASTXML_LOCALSRC=1
make

If castXML build complains about missing clang or llvm command, please go into $(GIMLISRC)/../thirdParty/build-XXX-XXX/castXML and try configure and build cmake manually

CC=clang-3.6 CXX=clang++-3.6 cmake ../../src/castXML/
make

If you build castXML manually you can provide this binary to cmake via

cmake ../gimli -DCASTER_EXECUTABLE=$(PATH_TO_CASTXML)

You can rebuild and update all local generated third party software by setting the CLEAN environment variable:

CLEAN=1 cmake ../gimli

Use alternative c++ compiler.

CC=clang CXX=clang++ cmake ../gimli

Define alternative python version. On default the version of your active python version will be chosen. You will need numpy and boost-python builds with your desired python version.

cmake ../gimli -DPYVERSION=3.6

Build the library with debug and profiling flags

cmake ../gimli -DCMAKE_BUILD_TYPE=Debug

Build the library with gcc build.in sanity check

cmake ../gimli -DCMAKE_BUILD_TYPE=Debug -DASAN=1

More verbose build output to view the complete command line:

make VERBOSE=1

To build pyGIMLi from source, the following tools are required:

  • subversion, git, mercurial, wget, tar

  • cmake >= 2.8.10

  • gcc >= 4.4

  • >=Python-3.5 | >=Python-2.7

  • numpy-dev

  • >=matplotlib-3.0

  • >=clang++-3.6.0 (3.7.0, 3.8.0)

  • libclang-3.7-dev

  • >=llvm-3.6.0 (3.7.0, 3.8.0)

  • libz-dev

  • python-setuptools

    tested on:

    • gentoo x86_64: gcc-4.4.5, gcc-4.5.3, gcc-4.5.4, gcc-4.9.2 gcc-5.3.0

    • Debian 3.2.46-1 x86_64: gcc-4.7.2

    • Ubuntu 16.04 LTS with gcc-5.4.0

    • Arch Linux gcc-5.2.0

    • CentOS

    • MinGW32: gcc-4.6.2/4, gcc-4.7.2, gcc-5.2.0

    • MinGW64: gcc-4.5.4, gcc-5.2.0, gcc-6.3.0, gcc-7.1.0

These tools can be installed system-wide with your native package manager (i.e. apt-get). If not found, the provided build scripts will automatically download and compile the necessary components.

These tools are required to create the Python bindings and are likely to be outdated in your distribution and should therefore not be installed system-wide. The build scripts will install them automatically.

  • castxml

  • pygccxml

  • pyplusplus