Running Salome script without graphics

2019-05-09 13:03发布

I exported a script from Salome (dump), and I want to run it in python (I'm doing some geometric operation and I don't need any graphics). So I removed all the graphic command, but when I try to launch my python file, python cannot found the salome libraries.

I tried to export the salome path ('install_path'/appli_V6_5_0p1/bin/salome/) in PYTHONPATH and LD_LIBRARY_PATH but it still doesn't work.

I also would like to know if it's possible to use only the geompy library without salome, and if it's possible, how can I install only the geompy library? ( I need to launch some geompy script on a UAV with only 8gb of memory, so the less thing I install, the better)

标签: python dump
3条回答
小情绪 Triste *
2楼-- · 2019-05-09 13:37

I had similar wishes to you but after much searching I ended up concluding that what we both want to do is not completely possible.

In order to run a salome script on the command line without the GUI use

salome -t python script.py or simply salome -t script.py

In order to run a salome script you must call it using the salome executable. It seems that you cannot use the salome libraries (by importing them into a python script that is then called with python script.py) without the compiled program. The executables that salome uses contain much of what the platform needs to do its job.

This frustrated me for a long time, but I found a workaround; for a simple example, if you have a salome script you can call the salome executable from within another python program with os.system("salome -t python script.py")

But now you have a problem; salome does not automatically kill the session so if you run the above command a number of times your system will become clogged up with multiple instances of running salome processes. These can be killed manually by running killSalome.py, found in your salome installation folder. But beware! This will kill all instances of salome running on your computer! This will be a problem if you are running multiple model generation scripts at once or if you also have the salome GUI open.

Obviously, a better way is for your script to kill each specific instance of salome after it has been used. The following is one method (the exact paths to the executable etc will need to change depending on your installation):

# Make a subprocess call to the salome executable and store the used port in a text file:
subprocess.call('/salomedirectory/bin/runAppli -t python script.py --ns-port-log=/absolute/path/salomePort.txt', shell=True)

# Read in the port number from the text file:
port_file = open('/absolute/path/salomePort.txt','r')
killPort = int(port_file.readline())
port_file.close()

# Kill the session with the specified port:
subprocess.call('/salomedirectory/bin/salome/killSalomeWithPort.py %s' % killPort,shell=True)

EDIT: Typo correction to the python os command.

EDIT2: I recently found that problems with this method are met when the port log file (here "salomePort.txt" but can be named arbitrarily) is given with only its relative path. It seems that giving it with its full, absolute path is necessarily for this to work.

查看更多
霸刀☆藐视天下
3楼-- · 2019-05-09 13:41

According to Salome FAQ:

To launch SALOME without GUI, use “runSalome –t” command: only the necessary servers are launched (without GUI). To start an interactive Python console then (for example, to be able to load TUI scripts), you will need to use --pinter option

To launch Salome with only chosen modules:

To launch a group of chosen SALOME modules, use the command “runSalome –-modules=XXX,YYY”, where XXX and YYY are modules' names. You can use –h command to display help of runSalome script.

查看更多
男人必须洒脱
4楼-- · 2019-05-09 13:52

If you are working with salome on windows platform, use following

salome_folder\WORK>run_salome.bat -t script_file.py
查看更多
登录 后发表回答