Python - Shell Environment
April 7, 2006 12:17 PM Subscribe
Is there a way to set an environment variable in the unix shell from a python script? Can I set a variable in the shell that executes that same script? For that matter, is there a way for any script to do this?
posted by kuatto to Computers & Internet (8 answers total) 1 user marked this as a favorite
In other words, I am trying to set up a nice environment in my unix shell (potentially bash or tcsh), and I need to set up some custom paths. I would like to do this from a script.
It seems that,
MY_PATH = os.getenv('PATH', 'Error')
os.environ["PATH"] = MY_PATH + ':' + install_path + '/bin'
sets $PATH in some subshell spawned by python, and it doesn't update the environment of the shell that executes the python script.
I had this problem in trying to write a bash script as well.