Using meshio from a python script from salome

I need to export and re import my mesh into Salome going through the vtk format. Sadly this format is not supported by Salome therefore I need to use an intermediate format such as med. I would love to integrate this into my automatized workflow inside a salome python script. For the format changing of med to vtk I was thinking of using meshio to read the med format and export it in vtk. Nevertheless, meshio is not available out of the box in the python of Salome.
My first approach was to install the library inside the Salome python by using in the terminal
‘./salome shell’ and then use ‘pip install meshio’ this seamed to work but when trying to use meshio it gives an error about h5py library, I also tried to install it as with meshio but this one gives some errors.
My second though was to separate the meshio section into an another script and then run the second script from calling the terminal who at the same time called python (yeah quite messy but my only hope) for this I being trying subprocess but it also didn’t worked in Salome, and lastly I tested with os using 'os.system(“python3”) which didn’t gave any error but also didn’t do anything.
How could I conturnate this issue…? (or ideally export directly in vtk so I don’t need so much time in changing formats and writing unnecessary middle step files)
Best regards.

I understand you want to install meshio within SALOME. Can you share the error message and tell on which OS you’re trying to do this ?

Hello nabil,
I want to use meshio, ideally install it inside the python of salome to use it.
I actually need to be able to create my mesh → export it in vtk → re import it to salome ->continue working in my script saddly there is no possibility to export directly in vtk a mesh created in salome.
installing meshio does not give issues but when trying to use it see file (614 Bytes) (if you run this it will give you an error about its dependencies)
salome gives errors over some of meshio dependencies like h5py
and if I try to install pip install meshio[all] which installs everything in salome it crashes completly for several dependencies…
so I drop in a first time to install meshio inside of python salome and simply looked to succed in using it with os or subprocess but I havent succesfully achieved this neither.
if you have any suggestion in

  1. using meshio inside salome
  2. using it from calling it from python3 from the system

i would appreciate it

thanks for the description. Which SALOME version are you running (windows or linux and which Linux flavor if Linux, such that we can check on our side)

I am using:

  • linux universal
  • OS: tuxedo OS 2 (based in ubuntu)
  • version 9.11

I am having different issues with salome itself already (post).

Hello @NabilG any insight on how to solve this problem? I need to be able to export and then reimport vtk files during my python script as this is a blocking point right now for me.

Given that I don’t have access to Tuxedo OS, I gave it a try on one Ubuntu 20.04 workstation.
You can try the following command lines and see if it helps to resolve your issue to have meshio run with your script (I tried it on a box meshed with netgen):

Note that you can try other combinations for h5py and meshio versions to check if these are functional.
Hopefully we move to a more recent python version for the universal version, such that we support more recent python packages.

tar zxf SALOME-9.11.0.tar.gz
cd SALOME-9.11.0
chmod u+x ./
sed -i 's/BINARIES-CO7/INSTALL/g' mesa_salome
sed -i 's/BINARIES-CO7/INSTALL/g' salome
source ./
python -m pip install --upgrade pip
python -m pip install h5py==2.10.0 --no-deps
python -m pip install meshio==4.4.6 --no-deps
import meshio
# input file generated in SMESH
input_file_path = ""
# output file
output_file_path = "Mesh_1.vtk"
# read med file
mesh =
# convert the mesh to vtk
meshio.write(output_file_path, mesh)

Hello nabil, thanks for your help,
this might help me in the future, for the moment after posting, I took some time to dig into vtk format found this file with the vtk explenation format and created a python function to write my mesh in desired format (vtk directly from the mesh data, it is actually quite similar in structure with the annoying difference of nodes being noted from 1 in mesh and in other formats from 0), and the read I only need to read the points so I can work with classic python.
one last thing I would need guidance with (and that answer also my initial question):
how can I run a command that is in MY bash environment? I have in my .bashrc created an alias to an executable that I compiled on my machine. that looks like this ‘command input1 input2 N M’. I might be rushing my self, but pretty sure that if I run subprocess or os.system(‘command input1 input2 N M’) this will not work. I could also run os.system(‘pathToExecutable/executable input1 input2 N M’) (without using the alias) how can I achieve this?
best regards
and happy holydays!

Assuming your login shell is Bash, I understand that you have in you .bashrc some aliases that you want to call from your python session with os.system.
Instead of using an alias, i would instead use a function which is much more flexible and implement it in $HOME/.bashrc (or some file called say $HOME/.bash_functions that I load in my .bashrc)
Something like:

function vtkBuilder(){
    echo "INFO: calling vtkBuilder with parameters: $@"
    for p in $@; do
        echo "INFO: parameter: $p"

Then in a python session: call os.system like:

import os
os.system('/bin/bash -c -l "vtkBuilder --help"')

note that you can also use subprocess module methods.
Surely someone comes with a smarter suggestion.

PS: thanks for helping others in this forum!

1 Like

Hello @NabilG ,
I am affraid that this is not working for me.
In salome I runned

os.system('/bin/bash -c -l "rm -f '+path+nameOfMesh+'Output.vtk"')

os.system('/bin/bash -c -l "smoothing '+path+nameOfMesh+'.vtk '+path+nameOfMesh+'Output.vtk '+str(innerLoops_1)+' '+str(nProcessors)+'"')

while path=/home/franco/, nameOfMesh='testMesh' , innerLoops_1=20, nProcessors=8 thefore the commands (also if I remplace the os.system by print) I get:

/bin/bash -c -l "rm -f /home/Franco/testMeshOutput.vtk"
/bin/bash -c -l "smoothing /home/Franco/testMesh.vtk /home/Franco/testMeshOutput.vtk 20 8"

in my .bashrc I have a function as you mentionned:

smoothing() {
    local inp1="$1"
    local inp2="$2"
    local inp3="$3"
    local inp4="${4:-8}"  # Set default value for inp4 to 8

    OMP_NUM_THREADS="$inp4" /home/franco/Programs/smoothing/build/innerSmoother "$inp1" "$inp2" "$inp3"

and I got the following error (not sure why the flatpack errors) but if you look the last line ‘it does not found’

flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ version `XZ_5.2' not found (required by /lib/x86_64-linux-gnu/
flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/
flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/
id: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by id)
flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ version `XZ_5.2' not found (required by /lib/x86_64-linux-gnu/
flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/
flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/
id: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by id)
/bin/bash: line 1: smoothing: command not found

any idea? recommendation? this is blocking me to continue my current development so it is quite important :confused:

thanks in advance;

PS: thanks for helping others in this forum!

no problem, I struggled a lot (and still struggle with salome) so I try to give a hand when ever I can.
best regards

I believe there is something in your .bashrc which screws things up. I just gave it a try (using a dummy innnerSmoother program and it’s OK.
You could simply start from a fresh .bashrc without anything else than your function and check.

salome@salome-q:~/releases/SALOME-9.11.0$ source
salome@salome-q:~/releases/SALOME-9.11.0$ python
Python 3.6.5 (default, Jun  2 2023, 19:46:54)
[GCC 8.3.1 20190311 (Red Hat 8.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> nProcessors=5; path='/home/salome/';innerLoops_1=2; nameOfMesh='mesh'
>>> os.system('/bin/bash -c -l "smoothing '+path+nameOfMesh+'.vtk '+path+nameOfMesh+'Output.vtk '+str(innerLoops_1)+' '+str(nProcessors)+'"')
Entering innnerSmoother
Number of threads: 5

Hello nabil,
thanks for the insight, I went to not use the function in bashrc and symply create the complete original command inside the python string directly. this solved the issue.
best regards,

hello @NabilG ,
me again, sorry for bothering you.
I am still having trouble regarding this subject.
I have the following lines in my python script:

command='"vtkUnstructuredToFoam  '+nameOfMeshAndFile+'.vtk  -case '+path+' > '+path+'log.vtkUnstructuredToFoam"'
os.system('/bin/bash -c -l '+command)

if I print(command) i get

“vtkUnstructuredToFoam Mesh_1.vtk -case /home/franco/Desktop/pipe/ > /home/franco/Desktop/pipe/log.vtkUnstructuredToFoam”

if I copy paste this in the terminal (wihout the " " obviously) and run it, it works correctly nevertheless the os.system('/bin/bash -c -l '+command)
gives me the following error (in salome terminal):

flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ version `XZ_5.2’ not found (required by /lib/x86_64-linux-gnu/

flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/

flatpak: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by /lib/x86_64-linux-gnu/

id: /home/franco/Programs/SALOME-9.11.0/BINARIES-CO7/system_dep/ no version information available (required by id)

/bin/bash: line 1: vtkUnstructuredToFoam: command not found

so, as you can see from the last error, it is not detecting the command vtkUnstructuredToFoam
I should remark that the function itslef is sourced in the bashrc from another bashrc (the following line is in my $HOME/.bashrc:

source /usr/lib/openfoam/openfoam2306/etc/bashrc

any idea, solution?
PS. here is my .bashrc if necessary, but it doesnt have anything fancy, and also I have commented everything else outside of the source that I added myself, and still no luck.
bashrc.txt (5,7 KB)