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
Hover offers domain privacy protection and excellent customer support. * add your javascript code here. Financier and philanthropist jacob rothschild dies at 87 – cna.