I have issue with "os.environ.get" command. I exported my variable using:
export MYVAR="123"
Then i used:
echo "$MYVAR"
And it returned my value. But when i am doing in python
print(os.environ.get('MYVAR'))
It returns None. For example:
print(os.environ.get('HOME'))
Works correctly. I tried using bashrc, zhrsc, bash_profile and it never works. I am using Linux Elementary 5.1. How can I solve this problem?
Looks like your export of the environment variable is only limited to the shell you are using. If you set the environment variable system-wide, it will be available to be read in your python code as well.
Set environment variable in /etc/environment for Unix based system