direnv

An environment switcher for the shell.

Automate the activation of Python virtual environments

You can use it with, e.g., uv.

  1. Install it.
brew install direnv
  1. Hook direnv into the shell. For instance, add the following into .zshrc or .zshrc.local
eval "$(direnv hook zsh)" # for zsh
  1. Restart the shell or source it again.
  2. Go to the project directory and create .envrc file.
source .venv/bin/activate
  1. Give permission
direnv allow