operating system - Is it possible to set an environment variable from Python permanently? -


using os module can values of environment variables. example:

os.environ['home'] 

however, cannot set environment variables:

os.environ['bla'] = "foo" 

it works in current session of program when python program finished, not see changed (or set) values of environment variables. there way python?

if want make environment variables persist accross sessions, could

for unix

do when in bash shell. append environment variables inside ~/.bashrc.

import os open(os.path.expanduser("~/.bashrc"), "a") outfile:     # 'a' stands "append"       outfile.write("export myvar=myvalue") 

or windows:

setx /m myvar "myvalue" 

in *.bat in startup in program files


Comments