Skip to content

Instantly share code, notes, and snippets.

@mikhail
Last active January 29, 2016 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikhail/e545cc0beff5db7ebdd9 to your computer and use it in GitHub Desktop.
Save mikhail/e545cc0beff5db7ebdd9 to your computer and use it in GitHub Desktop.
Quick handling of python's virtualenv

The two functions (akt and mkvin) in this gist allow for a quick way to create end activate python's virtual environments

mkvin will create a new virtual environment in $HOME/virtualenvironments directory with the name of the directory you're in.

For example:

[mikhail@MadRussian git]$ mkdir projectzero
[mikhail@MadRussian git]$ cd projectzero
[mikhail@MadRussian projectzero]$ mkvin
New python executable in /Users/mikhail/virtualenvironments/projectzero/bin/python
Installing setuptools, pip, wheel...done.
(projectzero)[mikhail@MadRussian projectzero]$

akt will activate your local virtual environment. Either activating the conventional .venv directory, or if it is not found then searching for the one created via mkvin

function mkvin {
currentdir=${PWD##*/}
mkdir -p $HOME/virtualenvironments
venvdir=$HOME/virtualenvironments/${1-$currentdir}
virtualenv --no-site-packages $venvdir
source $venvdir/bin/activate
}
function akt {
currentdir=${PWD##*/}
venv=$HOME/virtualenvironments/${1-$currentdir}/bin/activate
localvenv=.venv/bin/activate
if [ -f "$localvenv" ]; then
source "$localvenv"
elif [ -f "$venv" ]; then
source "$venv"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment