A virtual environment is a “space” separated from operating system, where Python packages get installed. This “space” is local, thus prevents Python packages from overwriting your system Python packages.
Imagine having package
xyz in version
1.2.4 installed system-wide. Now
you want to install Ganeti Web Manager, that requires this package in version
You can’t keep both packages installed system-wide. Therefore you need to somehow separate packages required by Ganeti Web Manager and your system packages. Virtual environment does exactly this.
Virtual environment structure¶
Virtual environment (shortly
venv) consists of these
bin- contains executable files and activation scripts
include- contains symlink to
lib- Python packages get installed to this directory
local- contains symlinks to
share- contains documents and
manpages installed along with Python packages
Helpers and tools¶
Main tool used for creating virtual environments is
When you issue
virtualenv name in your shell, this tool creates structure
described above in the
Usually next thing to do when developing (or deploying) a project in Python is to clone a repository within that virtual environment. It creates your project files next to virtual environment’s directories. And everything becomes a mess.
To help overcome this mess, someone clever wrote
is a set of shell scripts, that:
create virtual environment in your
list virtual environments existing there
remove specified virtual environment
quickly switch between existing virtual environments
…and we highly recommend using it.
Creates virtual environment with given name.
List all existing virtual environments.
Remove existing virtual environment with given name.
Switch to virtual environment with given name.
When you’re within virtual environment, you can leave it by issuing this command.
Command line prompt¶
By default, after activating specific virtual environment, it’s name appears at the beginning of your shell prompt. For example:
$ cd ganeti_webmgr $ workon gwm (gwm)$ django-admin.py --help ... (gwm)$ deactivate $ lsvirtualenv
In some guides in this documentation these brackets indicate commands issued from within virtual environment.