Activate Python virtual environment automatically on iTerm2

RMAG news

1. Create a function in the .zshrc

# ~/.zshrc
activate() {
if [ -d “.venv” ]; then
source .venv/bin/activate
else
: # ignore if no .venv
fi
}

2. Set iTerm to call this function on a new tap

iTerm2: Preferences -> Profiles -> Command: Login Shell -> Send text at start: “activate”

https://minho42.com/posts/auto-activate-venv-on-iterm/

Leave a Reply

Your email address will not be published. Required fields are marked *