Lewis Morris
Lewis Morris

Reputation: 2124

os.environ.get returning None while the terminal returns correct environment variable

I've set the environment variable in the shell like this

export DEPLOY=development 

and running this returns "development"

echo $DEPLOY 

However... this returns none in python.

import os
os.environ.get("DEPLOY")

and this raises a key error

os.environ["DEPLOY"]

I've deleted the .pyc files and restarted my IDE...

Any ideas?

Upvotes: 0

Views: 1756

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295272

export DEPLOY=development only changes the environment for your shell, and programs that shell starts.

Because you're starting Python from your IDE, not from the shell, the Python interpreter is not a child (or grandchild) process of that shell, and so does not inherit the shell's environment variables.

Upvotes: 1

Related Questions