Search code examples
pythonlinuxjupyter-notebook

How to reload environment variables in Python?


I set up a systemctl service (Jupyter) as part of a bootstrap for a Hadoop cluster. After bootstrap actions are completed, Hadoop is installed. During that step a number of environment variables are set - and these are vital for my service, Jupyter. Problem is, Jupyter does not know these environment variables, as it is started earlier in the process.

My question: how can I reload environment variables for my user? At the moment the user is running Jupyter, all env variables are known - I just need them loaded into the Python interpreter.

This fails inside notebook: os.environ['JAVA_HOME'] but works fine in the interpreter (because JAVA_HOME was defined after Jupyter was started).


Solution

  • Environment variables are local to a process when it starts and inherited from the parent process I think you are not going to be able to set them from outside that process. You can set them in that process but you would need to establish some way to pass them in. (example put in file and have something on a thread periodically read and set them local to that process)