本文介绍了在没有图形的情况下运行Salome脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Salome(转储)中导出了一个脚本,我想在python中运行它(我正在做一些几何运算,不需要任何图形)。因此,我删除了所有图形命令,但是当我尝试启动python文件时,python无法找到salome库。

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.

我尝试导出salome路径('install_path '/ appli_V6_5_0p1 / bin / salome /)在PYTHONPATH和LD_LIBRARY_PATH中,但仍然无法正常工作。

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.

我还想知道是否有可能只使用风俗没有salome的库,如果可能,如何只安装geompy库? (我需要在只有8gb内存的无人机上启动一些简单的脚本,所以我安装的东西越少越好)

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)

推荐答案

我也有类似的愿望,但经过大量搜索,我最终得出结论,我们俩都想做的事并非完全可能。

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.

为了运行salome脚本在没有GUI的命令行上使用

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

salome -t python script.py
或简单地
salome -t script.py

要运行salome脚本,您必须使用salome可执行文件。似乎如果没有编译的程序,就无法使用salome库(将它们导入python脚本,然后使用 python script.py 进行调用)。 salome使用的可执行文件包含平台完成其工作所需的大部分内容。

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.

这让我很久很沮丧,但我找到了解决方法;举一个简单的例子,如果您有salome脚本,则可以使用
os.system( salome -t python script.py)

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 withos.system("salome -t python script.py")

但是现在您遇到了问题; salome不会自动终止会话,因此,如果多次运行上述命令,系统将被多个运行salome进程的实例阻塞。可以通过运行salome安装文件夹中的killSalome.py手动将其杀死。但是要当心!这将杀死计算机上运行的所有 salome实例!如果您一次运行多个模型生成脚本,或者还打开了salome GUI,这将是一个问题。

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.

显然,更好的方法是让脚本在使用salome后杀死每个特定的salome实例。以下是一种方法(根据安装情况,可执行文件等的确切路径将需要更改):

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)

编辑:对python os命令的错字修正。

Typo correction to the python os command.

EDIT2:我最近发现,当端口日志文件(此处为 salomePort.txt)遇到此方法问题时, (任意命名)仅给出其相对路径。似乎给它完整的,绝对的路径是必须的。

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.

这篇关于在没有图形的情况下运行Salome脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 18:06