Shell Function to Enable Python Virtual Environement
It always cumbersome to enable Python virtual environment, it is something like:
. ./venv/bin/activate
Other alternatives:
. ../venv/bin/activate
source ../venv/bin/activate
Instead of typing any of these I added the following shell function:
cat << EOF >> ~/.zshrc
vact() {
# Check for common venv folders in the current directory
for dir in .venv venv env ../venv ; do
if [[ -f "$dir/bin/activate" ]]; then
source "$dir/bin/activate"
echo "Activated virtual environment in ./$dir"
return 0
fi
done
}
EOF
Now to enable the virtual environment I just type vact.