LearningMore

Unloading autoenv based on a directory

AutoEnv is a killer tool that will automatically activate your virtualenv environment based on the directory you are in (based on the contents of a .env file). But what happens when you move out of that directory? Unfortunately, the same environment stays activated until you land in a directory that contains a new .env file.

Simple workaround: place this .env somewhere high in your directory tree (possibly in the root)

if [ -n "$VIRTUAL_ENV" ] ; then
    deactivate
fi

I dropped the above .env file into my user’s root folder, changed directories above my current directory and my virtualenv environment quickly changed. Thanks to kazagistar who suggested the fix!

 

Exit mobile version