Install additional python packages in Persalys environment

Hi everyone,

I’m facing an issue trying to import a particular package called ‘h5py’ (HDF5 for Python — h5py 3.8.0 documentation) in a Python script.

In the definition window of “Coupling model”, I call for the script with the command :
python script.py

#script.py
import sys
sys.path.append(‘absolute-path\to-external-site-packages\containing-h5py’)
import h5py

I get a circular import error which probably comes from a bad architecture of the library.
However, I have no problem to import h5py in an external environment.

To try to solve the problem, I would like to know how to install a library in the Persalys site-packages via a pip command.

Thank you!

Hi and welcome to the forum,

You should be able to install specific python packages using the python console (Tools>Python console) within Persalys.
In there, you can enter the following:

import subprocess
subprocess.run(['pip', 'install', 'h5py'])

Please let me know if that helps
Cheers

Guillaume

1 Like

It is working, thank you!

Hi to both of you, I would like to add a few comments: running subprocess as indicated above does not always work well; in my case I had to enter the following:

import subprocess
subprocess.run(['python', '-m', 'pip', 'install', 'h5py'])

additionally, it may be necessary to specify a proxy (say, “http://myproxy.com”) by adding:

import subprocess
subprocess.run(['python', '-m', 'pip', 'install', '--proxy=http://myproxy.com', 'h5py'])

Hello,

In the new release 16.1, we have added an internal Python module that helps to install extra Python module. Whether you use Linux or Windows, it is the same command:

from nopip import install
install.modules(["<module_name>", "--user"], verbose=True)

More information are provided in the documentation.

Regards,
Antoine