Search code examples
pythonapache-sparkenvironment-variablespython-os

Unable to get environment variables using os python


I recently created two environment variables in my terminal as shown below

export SPARK_HOME='/opt/spark/'
export HAIL_HOME='/home/ABCD/.pyenv/versions/3.7.2/envs/bio/lib/python3.7/site-packages/hail/'

When I use echo $SPARK_HOME or echo $HAIL_HOME, I am able to see the path as output

But, when I use the below os commands in jupyter notebook

os.getenv('SPARK_HOME')  # able to get the output /opt/spark/
os.getenv('HAIL_HOME')   # returns no output

I also tried defining the same variables from jupyter as well using os.putenv but even then,I see output only for SPARK_HOME

However, I am able to see in my terminal screen the environment variablesSPARK_HOME and HAIL_HOME using printenv command

Can help me understand what's the problem?


Solution

  • I realized that it doesn't produce output for HAIL_HOME because it is installed in my virtual environment. (see .pyenv which is a hidden folder for my virtual environment`)

    However, if anyone can confirm this it's even better