what is it?

  • augments existing shells with a new feature that can load and unload environment variables depending on the current directory
  • can be used to automatically activate a python virtual environment

installation

sudo apt install direnv

edit shell .rc file (example for zsh, see documentation for other shells)

.zshrc
eval "$(direnv hook zsh)"

configuration

in python project directory containing the virtual environmment directory create a .envrc file

cd <PYTHON_PROJECT>
vim .envrc
.envrc
source <VENV_NAME>/bin/activate
unset PS1

allow direnv to make the changes direnv allow