Search code examples
pythonjupyter-notebookoperating-systempython-os

os.getenv returns empty output - python


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?


Solution

  • 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.