Environment Variables inside Python virtualenvs
It’s all about scope.
Working environments is made even better by defining some variables that are only active in that specific environment.
Set Variables
navigate to $VIRTUAL_ENV/bin/postactivate
export FIRST_NAME="Sam" export LAST_NAME="Gutentag"
Unset Variables
navigate to $VIRTUAL_ENV/bin/predeactivate
unset FIRST_NAME unset LAST_NAME
Verify Variables are being Set and Unset correctly
In this example, use the command $ printenv | grep _NAME
- Before activating the virtualenv, it should return no results
- After activating the virtualenv, it should return our variables
- After deactivating the virtualenv, it should return no results