virtualenvwrapper 4.8.4

virtualenvwrapper is a set of extensions to Ian Bicking’s virtualenv tool. The extensionsinclude wrappers for creating and deleting virtual environments andotherwise managing your development workflow, making it easier to workon more than one project at a time without introducing conflicts intheir dependencies.

Features

  • Organizes all of your virtual environments in one place.
  • Wrappers for managing your virtual environments (create, delete,copy).
  • Use a single command to switch between environments.
  • Tab completion for commands that take a virtual environment asargument.
  • User-configurable hooks for all operations (see Per-User Customization).
  • Plugin system for more creating sharable extensions (seeExtending Virtualenvwrapper).

Introduction

The best way to explain the features virtualenvwrapper gives you is toshow it in use.

First, some initialization steps. Most of this only needs to be doneone time. You will want to add the command to source/usr/local/bin/virtualenvwrapper.sh to your shell startup file,changing the path to virtualenvwrapper.sh depending on where it wasinstalled by pip or your package manager.

  1. $ pip install virtualenvwrapper
  2. ...
  3. $ export WORKON_HOME=~/Envs
  4. $ mkdir -p $WORKON_HOME
  5. $ source /usr/local/bin/virtualenvwrapper.sh
  6. $ mkvirtualenv env1
  7. Installing
  8. setuptools..........................................
  9. ....................................................
  10. ....................................................
  11. ...............................done.
  12. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/predeactivate
  13. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postdeactivate
  14. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/preactivate
  15. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postactivate New python executable in env1/bin/python
  16. (env1)$ ls $WORKON_HOME
  17. env1 hook.log

Now we can install some software into the environment.

  1. (env1)$ pip install django
  2. Downloading/unpacking django
  3. Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded
  4. Running setup.py egg_info for package django
  5. Installing collected packages: django
  6. Running setup.py install for django
  7. changing mode of build/scripts-2.6/django-admin.py from 644 to 755
  8. changing mode of /Users/dhellmann/Envs/env1/bin/django-admin.py to 755
  9. Successfully installed django

We can see the new package with lssitepackages:

  1. (env1)$ lssitepackages
  2. Django-1.1.1-py2.6.egg-info easy-install.pth
  3. setuptools-0.6.10-py2.6.egg pip-0.6.3-py2.6.egg
  4. django setuptools.pth

Of course we are not limited to a single virtualenv:

  1. (env1)$ ls $WORKON_HOME
  2. env1 hook.log
  3. (env1)$ mkvirtualenv env2
  4. Installing setuptools...............................
  5. ....................................................
  6. ....................................................
  7. ........... ...............................done.
  8. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/predeactivate
  9. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postdeactivate
  10. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/preactivate
  11. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postactivate New python executable in env2/bin/python
  12. (env2)$ ls $WORKON_HOME
  13. env1 env2 hook.log

Switch between environments with workon:

  1. (env2)$ workon env1
  2. (env1)$ echo $VIRTUAL_ENV
  3. /Users/dhellmann/Envs/env1
  4. (env1)$

The workon command also includes tab completion for theenvironment names, and invokes customization scripts as an environmentis activated or deactivated (see Per-User Customization).

  1. (env1)$ echo 'cd $VIRTUAL_ENV' >> $WORKON_HOME/postactivate
  2. (env1)$ workon env2
  3. (env2)$ pwd
  4. /Users/dhellmann/Envs/env2

postmkvirtualenv is run when a new environment iscreated, letting you automatically install commonly-used tools.

  1. (env2)$ echo 'pip install sphinx' >> $WORKON_HOME/postmkvirtualenv
  2. (env3)$ mkvirtualenv env3
  3. New python executable in env3/bin/python
  4. Installing setuptools...............................
  5. ....................................................
  6. ....................................................
  7. ........... ...............................done.
  8. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/predeactivate
  9. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postdeactivate
  10. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/preactivate
  11. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postactivate
  12. Downloading/unpacking sphinx
  13. Downloading Sphinx-0.6.5.tar.gz (972Kb): 972Kb downloaded
  14. Running setup.py egg_info for package sphinx
  15. no previously-included directories found matching 'doc/_build'
  16. Downloading/unpacking Pygments>=0.8 (from sphinx)
  17. Downloading Pygments-1.3.1.tar.gz (1.1Mb): 1.1Mb downloaded
  18. Running setup.py egg_info for package Pygments
  19. Downloading/unpacking Jinja2>=2.1 (from sphinx)
  20. Downloading Jinja2-2.4.tar.gz (688Kb): 688Kb downloaded
  21. Running setup.py egg_info for package Jinja2
  22. warning: no previously-included files matching '*' found under directory 'docs/_build/doctrees'
  23. Downloading/unpacking docutils>=0.4 (from sphinx)
  24. Downloading docutils-0.6.tar.gz (1.4Mb): 1.4Mb downloaded
  25. Running setup.py egg_info for package docutils
  26. Installing collected packages: docutils, Jinja2, Pygments, sphinx
  27. Running setup.py install for docutils
  28. Running setup.py install for Jinja2
  29. Running setup.py install for Pygments
  30. Running setup.py install for sphinx
  31. no previously-included directories found matching 'doc/_build'
  32. Installing sphinx-build script to /Users/dhellmann/Envs/env3/bin
  33. Installing sphinx-quickstart script to /Users/dhellmann/Envs/env3/bin
  34. Installing sphinx-autogen script to /Users/dhellmann/Envs/env3/bin
  35. Successfully installed docutils Jinja2 Pygments sphinx (env3)$
  36. (venv3)$ which sphinx-build
  37. /Users/dhellmann/Envs/env3/bin/sphinx-build

Through a combination of the existing functions defined by the corepackage (see Command Reference), third-party plugins (seeExtending Virtualenvwrapper), and user-defined scripts (see Per-User Customization)virtualenvwrapper gives you a wide variety of opportunities toautomate repetitive operations.

Details

References

virtualenv, from IanBicking, is a pre-requisite to using these extensions.

For more details, refer to the column I wrote for the May 2008 issueof Python Magazine: virtualenvwrapper | And Now For SomethingCompletely Different.

Manuel Kaufmann has translated this documentation into Spanish.

Tetsuya Morimoto has translated this documentation into Japanese.

Support

Join the virtualenvwrapper Google Group to discussissues and features.

Report bugs via the bug tracker on BitBucket.

Shell Aliases

Since virtualenvwrapper is largely a shell script, it uses shellcommands for a lot of its actions. If your environment makes heavyuse of shell aliases or other customizations, you may encounterissues. Before reporting bugs in the bug tracker, please testwithout your aliases enabled. If you can identify the alias causingthe problem, that will help make virtualenvwrapper more robust.

License

Copyright Doug Hellmann, All Rights Reserved

Permission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name of Doug Hellmann not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.

DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NOEVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT ORCONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OFUSE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OROTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE ORPERFORMANCE OF THIS SOFTWARE.