Activate Python virtual environment automatically on iTerm2

1. Create a function in the .zshrc

# ~/.zshrc
activate() { if [ -d ".venv" ]; then source .venv/bin/activate else : # ignore if no .venv fi
}
Enter fullscreen mode
Exit fullscreen mode

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/


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

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

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Quick setup dedicated servers (tbd). Artificial intelligence solid future. Please set api key.