Skip to content

Instantly share code, notes, and snippets.

@okken
Last active June 26, 2019 13:40
Show Gist options
  • Save okken/6d5f0dd69807ae9a558a052b9b9c299d to your computer and use it in GitHub Desktop.
Save okken/6d5f0dd69807ae9a558a052b9b9c299d to your computer and use it in GitHub Desktop.
venv activate/exit (windows version)
# 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