Pycharm(linux)中无法识别LD_LIBRARY_PATH

问题描述 投票:0回答:2

我正在尝试从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解释器。

pycharm environment-variables
2个回答
0
投票

出于某种原因,我第二天再次尝试,Pycharm现在能够看到变量。我尝试不同的唯一方法就是在Run->Edit Configurations的右上角勾选我的特定python脚本的共享框。即使我之后取消它,变量仍然被识别。当我应用更改时脚本变亮了,就像它从某个状态变为另一个状态一样,但我不知道我修改了什么。


0
投票

我在Ubuntu 16.04上遇到了Pycharm-2018.3的问题。

这是解决方案:

运行 - >编辑配置 - >环境 - > Add LD_LIBRARY_PATH picture1

picture2

而惊人的发生。

© www.soinside.com 2019 - 2024. All rights reserved.