Skip to content

Instantly share code, notes, and snippets.

@mikhail

mikhail/README.md

Last active Jan 29, 2016
Embed
What would you like to do?
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