我正在尝试从Pycharm中的python脚本运行一个名为“Cyclotron”的Geant4(粒子模拟引擎)可执行文件。当我从命令行执行它时,文件运行完全正常,即./Cyclotron
。
当我尝试使用subprocess.check_call()
方法执行相同的bash命令时,我收到以下错误消息:
./Cyclotron: error while loading shared libraries: libG4zlib.so:
cannot open shared object file: No such file or directory
Traceback (most recent call last):
File "/home/nicolas/Geant4/geant4.10.04.p01/main_stuff/cyclotron-
geant4/main.py", line 17, in <module>
subprocess.check_call(command.split())
File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['./Cyclotron']' returned non-
zero exit status 127.`
这似乎是由于在Pycharm中无法识别LD_LIBRARY_PATH
变量这一事实。例如,跑步
import os
print(os.environ.get("LD_LIBRARY_PATH"))
返回None
。我见过人们建议在Run->Edit Configurations
下进行,并在环境变量下添加变量(我已经尝试过我的脚本和默认值下的Python)但仍然没有运气。
在命令行上,键入echo $LD_LIBRARY_PATH
将返回/home/nicolas/Root/build/lib:/usr/lib/x86_64-linux-gnu:/home/nicolas/Geant4/install/lib
。
这是我的python代码:
import subprocess
import os
os.chdir("build")
bash_commands = [
"cmake ..",
"make -j4",
"./Cyclotron"
]
for command in bash_commands:
subprocess.check_call(command.split())
和输出:
/home/nicolas/PycharmProjects/Main/venv/bin/python
/home/nicolas/Geant4/geant4.10.04.p01/main_stuff/cyclotron-geant4/main.py
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/nicolas/Geant4/geant4.10.04.p01/main_stuff/cyclotron-geant4/build
[100%] Built target Cyclotron
$LD_LIBRARY_PATH
./Cyclotron: error while loading shared libraries: libG4zlib.so: cannot
open shared object file: No such file or directory
Traceback (most recent call last):
File "/home/nicolas/Geant4/geant4.10.04.p01/main_stuff/cyclotron-
geant4/main.py", line 14, in <module>
subprocess.check_call(command.split())
File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['./Cyclotron']' returned non-zero
exit status 127.
Process finished with exit code 1
我正在使用Ubuntu 18.04,Pycharm 2018和Python 3.6解释器。