Simple python venv wrapperΒΆ



You need virtualenv and pip for this to work.

VirtualEnvWrapper is a common wrapper to use Python’s virtual envs. However, thats a huge script to save a few lines of typing. And I don’t like huge scripts too much, specially if they’re not part of the main distribution of a project.

So I put this in my shell profile/rc:

#replace virtualenv2 by virtualenv if needed.
#virtualenv2 just means i'm using python2 and have python3 as main interpreter)
function mkvenv() {
        mkdir -p ~/.virtualenvs/$1
        virtualenv2 --no-site-packages ~/.virtualenvs/$1
        source ~/.virtualenvs/$1/bin/activate
function rmvenv() {
        rm -rf ~/.virtualenvs/$1
function lsvenvs() {
        ls ~/.virtualenvs

Then you can just go with:

$ mkvenv my_project
(my_project)$ pip install django;pip install blah

(my_project)$ pip freeze > requirements.txt
(my_project)$ deactivate
$ lsvenvs
$ rmvenv my_project

See also: