I can't seem to get my code to respond to custom environment variables so I wrote a piece of code to test it. os.getenv
is not pulling the environment variables that I've set in BASH into my Python code.
$ FRUSTRATION="PYTHON!!"
$ echo $FRUSTRATION
PYTHON!!
$ ipython
In [1]: import os
In [2]: very_frustrated = os.getenv("FRUSTRATION")
In [3]: print(very_frustrated)
None
echo FRUSTRATION
without a leading$
would repeatFRUSTRATION
, not the contents of the variable. At a guess, you didn't actuallyexport FRUSTRATION
in the shell you launchedipython
from. – Cozipython
from the same shell? – Vocable!!
is a shortcut for the previous command. If you simply meant it for emphasis, a different method would be good. – Naborsexported
. You just need to write:export FRUSTRATION="PYTHON!!"
and it will work. This is a duplicate of python - os.getenv and os.environ don't see environment variables of my bash shell. – Duperyzsh
and then running the python script frombash
the variable won't show up in os.environ – Veasey