Search code examples
pythonenvironment-variableskeyerror

Python: os.environ KeyError after export


Why python can't get evironment variable after export? How to fix this?

λ: export AUTOTEST=/home/anton/eltx/scripts/gitlab/
~
λ: python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['AUTOTEST']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
    raise KeyError(key)
KeyError: 'AUTOTEST'
>>> 
>>> os.environ.get('AUTOTEST', 'none_value')
'none_value'
>>>

Solution

  • I found the mistake. There was an alias for running python