direnv
An environment switcher for the shell.
Automate the activation of Python virtual environments
You can use it with, e.g., uv.
- Install it.
brew install direnv
- Hook
direnv
into the shell. For instance, add the following into.zshrc
or.zshrc.local
eval "$(direnv hook zsh)" # for zsh
- Restart the shell or source it again.
- Go to the project directory and create
.envrc
file.
source .venv/bin/activate
- Give permission
direnv allow