os.getenv返回空输出-python [英] os.getenv returns empty output - python
问题描述
我是python的新手,在执行os命令时遇到一些问题.
I am new to python and encountering some issues while executing os commands.
我已如下所示设置了environment variables
SPARK_HOME = '/opt/spark'
HAIL_HOME = '/opt/hail/hail'
当我键入os.getenv('SPARK_HOME')
时,我得到以下输出
When I type os.getenv('SPARK_HOME')
, I get the below output
'/opt/spark/'
但是当我键入os.getenv('HAIL_HOME')
时,会得到空白输出
But when I type os.getenv('HAIL_HOME')
, I get blank output
请注意,我是使用jupyter笔记本从虚拟环境中键入上述两个命令的.
Please note that I type the above two commands from a virtual environment using jupyter notebook.
- 为什么它适用于
spark
并为hail
返回空
- Why it works for
spark
and returns empty forhail
可以指导我解决这个问题吗?
Can guide me with this issue?
推荐答案
基于我们在聊天中的讨论,确定了几个问题.
Based on our discussion on chat, identified several issues.
变量设置与环境变量设置混淆.因此设置它们的正确方法应该是:
Variable setting is confused with env variable setting. So correct way to set them should be like:
os.putenv('SPARK_HOME', '/opt/spark')
os.putenv('HAIL_HOME', '/opt/hail/hail')
即使错误地尝试设置env变量,SPARK_HOME也会显示正确的值,因为jupyter进程会从shell继承该变量.
Even the mistaken env variable set attempts, SPARK_HOME shows the correct value because jupyter process inherits that variable from the shell.
这篇关于os.getenv返回空输出-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!