[英]Python, Pycharm - missing environment variables in os.environ
使用 Python 3.6、PyCharm 2019.3.1 CE、64 位 Ubuntu 18.04
我有一个环境变量,在从命令行运行我的 python 脚本时可以正常访问,但在使用 PyCharm 运行时没有显示。
这是脚本:
import os
print(os.environ.get("GENICAM_GENTL64_PATH"))
从终端来看,这是我的 output:
:/usr/lib/ids/cti
在使用 PyCharm 时,这是我的 output:
None
这里发生了什么? 为什么使用 PyCharm 运行时环境变量不显示?
当您从终端运行 python 时,python 脚本会从 shell 继承环境变量,而后者又会通过 /etc.profiled 中的启动脚本获取GENICAM_GENTL64_PATH
。 (见文档)。
In contrast, when you start the script from PyCharm, there is no shell - PyCharm starts the python process itself - so you won't have the environment variables that populated by /etc/profile.d.
您可以通过从终端启动 PyCharm 来解决它,如此处所述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.