Last active
June 26, 2019 13:40
-
-
Save okken/6d5f0dd69807ae9a558a052b9b9c299d to your computer and use it in GitHub Desktop.
venv activate/exit (windows version)
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
# create virtual environment | |
# | |
function create { | |
echo "\ncreating virtual environment" | |
python -m venv venv --prompt ${PWD##*/} | |
echo "upgrading pip" | |
venv/Scripts/python.exe -m pip install -U pip | |
if [ -f requirements.txt ] | |
then | |
echo "installing dependencies from requirements.txt" | |
venv/Scripts/pip.exe install -r requirements.txt | |
fi | |
} | |
# activate a virtual environment | |
# | |
function activate { | |
if [ -d venv ] | |
then | |
source venv/Scripts/activate | |
else | |
echo "not in a directory with a venv" | |
read -p "create one? " -n 1 -r | |
echo # line break | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
create | |
source venv/Scripts/activate | |
fi | |
fi | |
} | |
# deactivate a virtual environment | |
# | |
alias exit="deactivate" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment