5

As you can see on the picture below, I have 'SPARK_HOME' environment variable:

enter image description here

However I just can't get it through python:

import os
os.environ.get('SPARK_HOME', None)  # returns None
"SPARK_HOME" in os.environ          # returns False

What am I doing wrong? Operating system is Windows 7 PS: I can get other variables, for example:

spark_home = os.environ.get('PYTHONPATH', None)
print spark_home  # returns correct path
3
  • @idjaw nice link, honestly I initially tried almost all pieces of code from the linl Commented Sep 20, 2016 at 12:34
  • 1
    The environment variable editor sends an "Environment" WM_SETTINGCHANGE message to top-level windows. Explorer see this message and reloads its environment from the registry values; it's pretty much the only program that looks for this message. Console programs generally don't even own any windows. You need to start a new instance of cmd.exe or python.exe with Explorer as the parent, so it will inherit the updated environment. Commented Sep 20, 2016 at 14:19
  • Total Commander looks also for WM_SETTINGCHANGE and updates also its own environment variable list which contains also some Total Command related environment variables. That can be seen on starting cmd.exe from within Total Commander and run set. Then a user or system environment variable is added/modified using Windows System Control Panel and after closing Environment Variables dialog window with button OK, one more cmd.exe is started from within Total Commander and set is executed also in this second command process instance. The added/modified variable is shown in second cmd. Commented Apr 18, 2020 at 16:49

1 Answer 1

14

To get your python start seeing new variables you need to restart your console, not just only ipython notebook!!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.