you can try to setup SALOME runtime environment with the env_launch.sh script.
This will ensure that your PYTHONPATH,LD_LIBRARYPATH, etc… environment variables are consistently set and expand yours.
nitawa:/software/SALOME/releases/SALOME-9.10.0> source env_launch.sh
import Python 3.6.5 (default, Dec 2 2022, 21:44:27)
[GCC 8.3.1 20190311 (Red Hat 8.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import salome
hello @Umut ,
just to be clear, correct me if i am wrong,
but if I want to run a salome script usign python3 directly, something like, python3 script.py I should add in the begining of the script.py, the line source $PATH/env_launch.sh ,where $PATH is the path where the env_launch.sh file is located?
source env_launch.sh is not a python command, you should run it in terminal before you run your python code. After that, your python codes should be able to run import salome. At least this was my case. Check the env_launch.py file briefly, it sets the environment variables required to import salome.
I was able to run my python scripts via python ./myScript instead of salome -t python myscript.py without any change in the script.
Side note: When I try to run the python script from pycharm instead or terminal I failed again, but this is because I made a mess about my python settings in pycharm.
thanks for the explenation,
I know that is not a python command, thats why i was not understanding. a simple work around would be to use os to run the bash command no?
so adding this to the python script:
#the rest of the python script
this if my brief understanding is correct would make it run correctly using python3 myScript.py
and could also be runned in pycharm or other editors.
Sorry to bother you again. I noticed that after I run the source env_launch.sh my python version has changed. Therefore I cant use other packages which are installed in another python version. Is it possible for me to import salome without changing my python version?
I could use help with a similar thing too. I am using Windows and VSCode as I mentioned before. It’s fine for me to use the SALOME python but then I want to change to another python afterwards without relaunching VSCode. Is that possible?
Or how can I install Meshio and Pyvista in SALOME python env? I did try to install them with “python -m pip install [Package]” but they give an error when importing them after importing salome (and only if I use it after salome, it works if I use meshio first). This is the error:
File “c:/PythonAPI/TwoLayerF.py”, line 11, in
mesh = meshio.read(‘C:/S9/Compound_Mesh_3.med’)
File “C:\S9\W64\Python\lib\site-packages\meshio_helpers.py”, line 69, in read
File “C:\S9\W64\Python\lib\site-packages\meshio\med_med.py”, line 36, in read
File “C:\S9\W64\Python\lib\site-packages\h5py_init_.py”, line 33, in
from . import version
File “C:\S9\W64\Python\lib\site-packages\h5py\version.py”, line 15, in
from . import h5 as _h5
File “h5py\h5.pyx”, line 1, in init h5py.h5
ImportError: DLL load failed: The specified procedure could not be found.
Looks like it fails at “import h5py” but that is successfully installed as well.