🎁 Environment Variables inside Python virtualenvs

January 29, 2020 (4y ago)

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

{% highlight bash %} export FIRST_NAME="Sam" export LAST_NAME="Gutentag" {% endhighlight %}

Unset Variables

navigate to $VIRTUAL_ENV/bin/predeactivate

{% highlight bash %} unset FIRST_NAME unset LAST_NAME {% endhighlight %}

Verify Variables are being Set and Unset correctly

In this example, use the command $ printenv | grep _NAME