Welcome to the forums. Please post in English or French.

You are not logged in.

#1 2021-01-02 16:32:46

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

[SOLVED] Install new package in salome_meca python distribution

I am trying to install the package (pandas) with the command:

sudo python3.6 -m pip install --install-option="--prefix=/home/username/salome_meca/V2019.0.3_universal/prerequisites/Pandas-120" pandas

It raises an error: Requirement already satisfied: pandas in /usr/lib/python3/dist-packages

And I cannot import this module as the python (3.6.5) distribution in Salome_meca cannot find it, when I run the code in the Salome_meca invornment.

Last edited by lskrinjar (2021-01-07 20:55:34)

Offline

#2 2021-01-04 11:08:42

Irvise
Member
Registered: 2019-12-07
Posts: 61

Re: [SOLVED] Install new package in salome_meca python distribution

Hello Iskrinjar,

I am not very well versed with how the Python module system works. However, a lot of the problems regarding Python in salome are due to the environment variables not being set correctly.

Take a look at these two other posts, maybe they will help you. At least one of them will make the Python environment of salome available to your computer.

code-aster.org/forum2/viewtopic.php?id=25323

code-aster.org/forum2/viewtopic.php?id=25234

Regards,

Fernando Oleo Blanco

Offline

#3 2021-01-04 17:42:06

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

Re: [SOLVED] Install new package in salome_meca python distribution

Irvise wrote:

Hello Iskrinjar,

I am not very well versed with how the Python module system works. However, a lot of the problems regarding Python in salome are due to the environment variables not being set correctly.

Take a look at these two other posts, maybe they will help you. At least one of them will make the Python environment of salome available to your computer.

code-aster.org/forum2/viewtopic.php?id=25323

code-aster.org/forum2/viewtopic.php?id=25234

Regards,

Fernando Oleo Blanco

Hello Fernando,
thank you for the suggestions. I have checked the links you suggested... the first link (code-aster.org/forum2/viewtopic.php?id=25323) is actually the exact oposite of what I would like. The second link (code-aster.org/forum2/viewtopic.php?id=25234) is similar up to the point when the command is executed:
$ source ./V2019.0.3_universal/salome_prerequisites.sh

unfortunately with the command: sudo -H python3.6 -m pip install pandas --target=/home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Pandas-120 I have managed to install the package to the requested directory, but in this folder it also installed other packages (numpy-1.19.4 pandas-1.1.5 python-dateutil-2.8.1 pytz-2020.5 six-1.15.0
).

I ran the YACS script once again the problem is not solved.

Last edited by lskrinjar (2021-01-04 20:43:26)

Offline

#4 2021-01-05 10:25:42

Irvise
Member
Registered: 2019-12-07
Posts: 61

Re: [SOLVED] Install new package in salome_meca python distribution

Hi Iskrinjar,

I understand your problem better now. I suppose that you are writing a Python script within YACS that makes use of Pandas, is that right?

And that is indeed quite strange. Salome should export all of its requirements when booting, so that they should be available when needed. That, of course, includes YACS...

I am going to test it and I will report back.

Regards,

Fer

Offline

#5 2021-01-05 11:40:38

Irvise
Member
Registered: 2019-12-07
Posts: 61

Re: [SOLVED] Install new package in salome_meca python distribution

Hi,

I think I found the solution(s). The problem is PYTHONPATH. That variable holds the directories where python will look for packages. Salome sets its own PYTHONPATH. So, here are the options:

Add pandas to salome's environment. For this, you would have to modify the file "V2019.0.3_universal/salome_prerequisites.sh". If you take a look at another python module, it will be obvious how to do it. Since you installed pandas already under the prerequisites folder, this may be the best way to go.

The alternative is to add your system path to salome's environment. I do not know if this is a good idea, since python versions may differ (if you have issues, maybe a virtual_env will help). To do this, I would recommend that you take a look at this two links, it is pretty simple.

stackoverflow.com/questions/247770/how-to-retrieve-a-modules-path
xmodulo.com/change-syspath-pythonpath-python.html

Regards,

Fer

Offline

#6 2021-01-06 19:14:58

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

Re: [SOLVED] Install new package in salome_meca python distribution

Irvise wrote:

Hi Iskrinjar,

I understand your problem better now. I suppose that you are writing a Python script within YACS that makes use of Pandas, is that right?

And that is indeed quite strange. Salome should export all of its requirements when booting, so that they should be available when needed. That, of course, includes YACS...

I am going to test it and I will report back.

Regards,

Fer

Hi Irvise,
yes, you are correct. I am trying to do something similar to the code on the link 'github.com/core-engineering/aster-calc-beam'. In YACS I am using an Inline Script Node in this Node I insert a python code and would like to import pandas package. But I cannot install it correclty to be found within salome_meca python distribution (OS Ubuntu 18.04.5 LTS). Your help is kindly appreciated, as I am running out of ideas. I will try your suggestion as suggested below and report it back.

Kind regards,
Luka

Last edited by lskrinjar (2021-01-06 20:07:22)

Offline

#7 2021-01-06 21:26:07

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

Re: [SOLVED] Install new package in salome_meca python distribution

Irvise wrote:

Hi,

I think I found the solution(s). The problem is PYTHONPATH. That variable holds the directories where python will look for packages. Salome sets its own PYTHONPATH. So, here are the options:

Add pandas to salome's environment. For this, you would have to modify the file "V2019.0.3_universal/salome_prerequisites.sh". If you take a look at another python module, it will be obvious how to do it. Since you installed pandas already under the prerequisites folder, this may be the best way to go.

The alternative is to add your system path to salome's environment. I do not know if this is a good idea, since python versions may differ (if you have issues, maybe a virtual_env will help). To do this, I would recommend that you take a look at this two links, it is pretty simple.

stackoverflow.com/questions/247770/how-to-retrieve-a-modules-path
xmodulo.com/change-syspath-pythonpath-python.html

Regards,

Fer

Hello Fernando,

regarding your first solution I have installed pandas package in the following steps:
./salome shell
sudo -H python3.6 -m pip install pandas --target=/home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Pandas-115

and this installed the following packages in this folder: numpy-1.19.5 pandas-1.1.5 python-dateutil-2.8.1 pytz-2020.5 six-1.15.0
(not sure if this is OK, because the structure in this folder Pandas-115 is not similar as the one of /prerequisites/Numpy-1151 as you suggested. And I cannot find in any of the subfolders /Pandas-115/ the folder /lib/ to add the line in file salome_prerequisites.sh as you suggested:
export PYTHONPATH="${PREREQUISITES_ROOT_DIR}/Pandas-115/lib/python3.6/site-packages":${PYTHONPATH}

I than run:
pip3 install pandas
And initially it raised an error (although looking good):
FileNotFoundError: [Errno 2] No such file or directory: '/home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Matplotlib-222/pytz-2015.2-py3.6.egg'

And tried one more time the last command and it returned:
Requirement already satisfied: pandas in /home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Python-365/lib/python3.6/site-packages (1.1.5)
Requirement already satisfied: pytz>=2017.2 in /home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Python-365/lib/python3.6/site-packages (from pandas) (2020.5)
Requirement already satisfied: numpy>=1.15.4 in /home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Python-365/lib/python3.6/site-packages (from pandas) (1.19.5)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Python-365/lib/python3.6/site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in /home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Matplotlib-222/six-1.12.0-py3.6.egg (from python-dateutil>=2.7.3->pandas) (1.12.0)

This looks OK to me. If I manage to install it correctly should I run the file salome_prerequisites.sh or is this done automatically each time at salome_meca startup?

Once again thank you very much for your kind help and usefull informations.
Best,
Luka

Last edited by lskrinjar (2021-01-06 21:28:24)

Offline

#8 2021-01-06 21:33:01

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

Re: [SOLVED] Install new package in salome_meca python distribution

Problem solved. Thanks a lot Fernando!
Best,
Luka

Last edited by lskrinjar (2021-01-06 21:33:40)

Offline

#9 2021-01-07 09:24:44

Irvise
Member
Registered: 2019-12-07
Posts: 61

Re: [SOLVED] Install new package in salome_meca python distribution

Hi Iskrinjar,

I am glad that got fixed. This is an important solution, so if you could please change the topic to "[SOLVED] Install new ..." that will help others find it.

Also, answering your question. Yes, salome_prerequisites.sh runs when salome boots.

Regards,

Fer

Offline

#10 2021-01-07 20:59:42

lskrinjar
Member
Registered: 2015-10-16
Posts: 30

Re: [SOLVED] Install new package in salome_meca python distribution

Irvise wrote:

Hi Iskrinjar,

I am glad that got fixed. This is an important solution, so if you could please change the topic to "[SOLVED] Install new ..." that will help others find it.

Also, answering your question. Yes, salome_prerequisites.sh runs when salome boots.

Regards,

Fer

Done - status [Solved] added, as suggested. Probably I should add the target location so the command should be someting like this at the end:
pip3 install pandas --target=/home/lskrinjar/salome_meca/V2019.0.3_universal/prerequisites/Pandas-115

and with this the package should be installed in the specified directory - I will try this sometime in the future on another VM and give the update.

Thank you once again also for the comment on the .sh file.

Best,
Luka

Offline