Concurrent installation of Python bindings

Hi,

I usually have different versions of preCICE installed on my system. For each release (I normally keep the last 2-3 releases) of preCICE I have normally have a Release and Debug build and a version with own changes . I manage them with a module system (in my case Lmod) in order to switch between them.

At the moment I use the Python bindings only for one of my installed preCICE versions. I assume that I could install the bindings with the --prefix option in order to put them all in separate directories and then update the PYTHONPATH acordingly.

Is this the way to go or is there a recommended way or manual that explains how to install the preCICE bindings such that I can use it with each of the versions?

Best,
Alex

Hi Alex,

I never had to deal with several concurrent installations of the python bindings, but generally it should work. Some recommendations:

  • Using venv for managing the different installations of the python-bindings correctly might be a good idea.
  • The python-bindings have to be able to discover the correct version of preCICE. If there is only one preCICE installation on your system (and it is installed the right way), this happens automatically. If you have multiple versions of preCICE, you could follow the approach suggested here. But since you are already using a module system, it might also work out of the box and you don’t even have to worry.
  • If you are using venv for switching between different versions of the python-bindings and Lmod for switching between different versions of preCICE, you will have to be careful that both systems are in sync and you do not accidentally mix version A of the python-bindings with version B of preCICE. I am not aware of a nice approach how to solve this.

At the moment I use the Python bindings only for one of my installed preCICE versions. I assume that I could install the bindings with the --prefix option in order to put them all in separate directories and then update the PYTHONPATH acordingly.

I am a bit unsure whether I am understanding this correctly. You can use the CMAKE_INSTALL_PREFIX to install preCICE at a custom location. For the python bindings you can use ----include-dirs and --library-dirs to provide a custom location. Like explained above, I would recommend using venv to take care of several installations of the python-bindings.

There might have been a --prefix option for the python-bindings in the past, but I’m not 100% sure. Could you provide a link?

Any experiences or feedback are highly appreciated. Like I said: I never had to deal with multiple installations of the python bindings and I would be very interested whether and how it works in practice!

Best regards,
Benjamin

One can drop the --user flag for the installation and compile/install the bindings with, for example,

python3 setup.py install --prefix=/tmp/pythonbindings

(Note to potential readers: Please do not install your bindings to /tmp if you want to actually use them.)

This will build the bindings and put the in the specified directory. One could add this to the PYTHONPATH then. This is easy in my setup with the environment modules. I have not tried combining the module system with venv yet.

I was thinking to maybe install the bindings directly into the preCICE directory. This would be somewhat logic (to me) and I could remove preCICE including its bindings by deleting the installation directory of preCICE.

Edit: I guess the --prefix option (among others) comes directly from Python or the build system itself so you did not implement this yourself.

@BenjaminRueth

I just wanted to add something as I did some more testing. My previous comments were mainly focusing on the old bindings for preCICE 1.6.X.

Today I played a bit around with, especially with focus on the new bindings for preCICE 2.0 (I used 2.0.2). In installed the new bindings (v.2.0.1.1) with

pip3 install --prefix=/home/jaustar/software/precice/2.0.2-debug-mpi-petsc-python/python .

Since the adapter uses the shared library, it seems to be enough to build the bindings once. Then, depending on which module I have loaded (preCICE Release or Debug) it points to the correct preCICE library:

$ module load preCICE/2.0.2-Debug-MPI-PETSc-Python
$ ldd precice.cpython-36m-x86_64-linux-gnu.so | grep precice
libprecice.so.2 => /home/jaustar/software/precice/2.0.2-debug-mpi-petsc-python/lib/libprecice.so.2
$ module load preCICE/2.0.2-Release-MPI-PETSc-Python
$ ldd precice.cpython-36m-x86_64-linux-gnu.so | grep precice
libprecice.so.2 => /home/jaustar/software/precice/2.0.2-release-mpi-petsc-python/lib/libprecice.so.2

Importing preCICE in a Python shell also works as expected.

I think I will try this approach for now and see how it works for me. If you need more input or my experiences with this approach, I can report back later. We can also move part of this to GitHub if this is the better platform.

1 Like