I'm working on Debian Jessie with Python 2. Why can't Python's environ see environment variables that are visible in bash?
# echo $SECRET_KEY xxx-xxx-xxxx # python >>> from os import environ >>> environ["SECRET_KEY"] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/root/.virtualenvs/prescribing/lib/python2.7/UserDict.py", line 23, in __getitem__ raise KeyError(key) KeyError: 'SECRET_KEY' I set these environment variables using /etc/environment - not sure if that's relevant:
SECRET_KEY=xxx-xxx-xxx I had to run source /etc/environment to get bash to see them, which I thought was strange.
UPDATE: printenv SECRET_KEY produces nothing, so I guess SECRET_KEY is a shell not an environment variable.
exportit./env/environmentwas for setting environment variables - is this incorrect?source /env/environmentonly sets variables in the shell, not environment variables accessible by child processes./etc/environmentmight be used to set environment variables (though it isn't a standard file, AFAIK, but it is referenced in Ubuntu, it seems); maybe, because it depends what you write in the file (or what is written in the file if you don't have control over its contents)./env/environmentused, not for shells at any rate.