Created
February 3, 2020 15:50
-
-
Save CloudCray/d412c80a92e07da35645d6e0fea5b0f6 to your computer and use it in GitHub Desktop.
Bash script to activate virtual environments by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# virtualenvs must be in `~/venv` | |
# save this as /usr/local/bin/activate | |
# file is sourced instead of executed - need read permissions only | |
# `sudo chmod 644 /usr/local/bin/activate` | |
# | |
VIRTUAL_ENV="/home/$USER/venv/$1" | |
export VIRTUAL_ENV | |
ACT_SCRIPT='source $VIRTUAL_ENV/bin/activate' | |
eval "$ACT_SCRIPT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I typically keep all my venvs in the same directory, rather than within the projects themselves. This script helps me swap between them quickly without having to remember any paths or do any directory voodoo. Just
source activate data_science
orsource activate flask_project
from anywhereUses
/home/$USER/venv
instead of~/venv
in case file is saved as rootRunning
deactivate
should exit the venv without any additional config