简体   繁体   English

os.getenv 返回空 output - python

[英]os.getenv returns empty output - python

I am new to python and encountering some issues while executing os commands.我是 python 的新手,在执行 os 命令时遇到了一些问题。

I have set my environment variables like as shown below我已经设置了我的environment variables ,如下所示

SPARK_HOME = '/opt/spark'
HAIL_HOME  = '/opt/hail/hail'

When I type os.getenv('SPARK_HOME') , I get the below output当我输入os.getenv('SPARK_HOME')时,我得到以下 output

'/opt/spark/'

But when I type os.getenv('HAIL_HOME') , I get blank output但是当我输入os.getenv('HAIL_HOME')时,我得到空白 output

Please note that I type the above two commands from a virtual environment using jupyter notebook.请注意,我使用 jupyter notebook 从虚拟环境中输入了上述两个命令。

  1. Why it works for spark and returns empty for hail为什么它适用于spark并为hail返回空

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')

Even the mistaken env variable set attempts, SPARK_HOME shows the correct value because jupyter process inherits that variable from the shell.即使是错误的 env 变量集尝试,SPARK_HOME 也会显示正确的值,因为 jupyter 进程从 shell 继承了该变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM