1

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?

The Great
  • 7,215
  • 7
  • 40
  • 128
  • HAIL_HOME should be 'HAIL_HOME', a string identifier not a variable. – sardok Jun 23 '20 at 08:08
  • Sorry, updated the post. Even with `HAIL_HOME`, It returns empty output – The Great Jun 23 '20 at 08:09
  • You may debug program's env variables by printing `os.environ`. If what you look for is missing there, you should probably add command or script that sets env variables and starts your app. – sardok Jun 23 '20 at 08:14
  • Can you please help me with the second part of your comment? which is `you should probably add command or script that sets env variables and starts your app` – The Great Jun 23 '20 at 08:16
  • May I know why the item that I am looking for is missing? – The Great Jun 23 '20 at 08:19
  • Env variables are set by another program probably the shell. If an env variable is missing, you should investigate at one level below, where python script is started/executed. Thats why, it could be useful to add steps about how you set env variables and run python script. – sardok Jun 23 '20 at 08:26
  • Yes, you are right. I set these variables in my python program jupyter notebook `SPARK_HOME = '/opt/spark' HAIL_HOME = '/opt/hail/hail'` – The Great Jun 23 '20 at 08:27
  • but don't know why I am able to get the path of (os.getenv) for one variable and not for the other – The Great Jun 23 '20 at 08:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/216475/discussion-between-the-great-and-sardok). – The Great Jun 23 '20 at 08:30

1 Answers1

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.

sardok
  • 1,086
  • 1
  • 10
  • 19