Python environment

In OGS we make use of Python packages at different stages, e.g.:

  • Conan at configure-time to install third-party dependencies
  • ogs-container-maker when the CI prepares its environment
  • TESPy for simulating thermal engineering plants in a benchmark
  • pvpython for pre- and post-processing

Python packages are usually installed via pip and virtualenv provides an isolated environment to install these packages to.

Poetry

We make use of poetry which is a wrapper for pip and virtualenv. We recommend to install poetry with your system package manager or:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

When configuring with CMake poetry creates a new virtual environment in the .venv-directory inside your build directory. It will also install required Python packages into this environment. You can see the current environment definition in the file pyproject.toml inside your build-directory.

To manually add Python packages run the following inside your build-directory:

poetry add python-package-name # e.g. poetry add numpy

To activate the environment run poetry shell (this opens a new shell) or for one-off commands run poetry run command, e.g. poetry run pip list.

Poetry & Conan

You can also install Conan with Poetry (so you don’t need to install it system-wide) with the CMake-option OGS_USE_CONAN=auto:

cmake ../ogs -DOGS_USE_CONAN=auto

Poetry & Benchmarks

You can use the argument PYTHON_PACKAGES on AddTest() to specifiy additional Python package dependencies.

The following example would install the latest version of numpy and pandas version 0.1.2:

AddTest(
    ...
    PYTHON_PACKAGES numpy pandas=0.1.2
    ...
)

This article was written by Lars Bilke. If you are missing something or you find an error please let us know. Generated with Hugo 0.74.3. Last revision: October 7, 2020
Commit: [web] Fix typos on Python environment page. c1f6b7988  | Edit this page on