os.getenv returns empty output - python

▼魔方 西西 提交于 2020-07-10 10:29:01

问题


I am new to python and encountering some issues while executing os commands.

I have set my environment variables like as shown below

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

When I type os.getenv('SPARK_HOME'), I get the below output

'/opt/spark/'

But when I type os.getenv('HAIL_HOME'), I get blank output

Please note that I type the above two commands from a virtual environment using jupyter notebook.

  1. Why it works for spark and returns empty for hail

Can guide me with this issue?


回答1:


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.



来源:https://stackoverflow.com/questions/62530145/os-getenv-returns-empty-output-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!