# Concurrent installation of Python bindings

**URL:** <https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230>\
**Category:** Installing preCICE\
**Tags:** python\
**Created:** [April 27, 2020, 9:57am UTC](https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230 "2020-04-27T09:57:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [April 27, 2020, 9:57am UTC](https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230/1 "2020-04-27T09:57:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BenjaminRodenberg](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/benjaminrodenberg/32/17_2.png) [@BenjaminRodenberg](https://precice.discourse.group/u/BenjaminRodenberg)\
**Post date:** [April 29, 2020, 11:05am UTC](https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230/2 "2020-04-29T11:05:52Z")

</div>

Hi Alex,

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

- Using [`venv`](https://docs.python.org/3/tutorial/venv.html) 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](https://github.com/precice/python-bindings#precice-at-custom-location-setting-paths). 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`](https://github.com/precice/precice/wiki/Building:-Using-CMake#options) to install preCICE at a custom location. For the python bindings you can use [`----include-dirs` and `--library-dirs`](https://github.com/precice/python-bindings#precice-at-custom-location-setting-paths) 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

---

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [April 29, 2020, 11:25am UTC](https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230/3 "2020-04-29T11:25:22Z")

</div>

> [@BenjaminRodenberg](#):
>
> I am a bit unsure whether I am understanding this correctly. You can use the [`CMAKE_INSTALL_PREFIX`](https://github.com/precice/precice/wiki/Building:-Using-CMake#options) to install preCICE at a custom location. For the python bindings you can use [`----include-dirs` and `--library-dirs`](https://github.com/precice/python-bindings#precice-at-custom-location-setting-paths) to provide a custom location. Like explained above, I would recommend using `venv` to take care of several installations of the `python-bindings` .

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

```bash
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.

---

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [April 30, 2020, 9:23am UTC](https://precice.discourse.group/t/concurrent-installation-of-python-bindings/230/4 "2020-04-30T09:23:08Z")

</div>

@BenjaminRodenberg

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

```bash
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:

```bash
$ 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.
