Reference Guide

virtualenv Command


virtualenv [OPTIONS] ENV_DIR

Where ENV_DIR is an absolute or relative path to a directory to create the virtual environment in.



show program’s version number and exit

-h, --help

show this help message and exit

-v, --verbose

Increase verbosity.

-q, --quiet

Decrease verbosity.


The Python interpreter to use, e.g., –python=python2.5 will use the python2.5 interpreter to create the new environment. The default is the interpreter that virtualenv was installed with (like /usr/bin/python)


Clear out the non-root install and start from scratch.


Give the virtual environment access to the global site-packages.


Always copy files rather than symlinking.


Make an EXISTING virtualenv environment relocatable. This fixes up scripts and makes all .pth files relative.


Unzip Setuptools when installing it.


Do not install setuptools in the new virtualenv.


Do not install pip in the new virtualenv.


Do not install wheel in the new virtualenv.


Directory to look for setuptools/pip distributions in. This option can be specified multiple times.


Provides an alternative prompt prefix for this environment.


Download preinstalled packages from PyPI.


Do not download preinstalled packages from PyPI.


DEPRECATED. Retained only for backward compatibility. Not having access to global site-packages is now the default behavior.


Legacy; now have no effect. Before version 1.10 these could be used to choose whether to install Distribute or Setuptools into the created virtualenv. Distribute has now been merged into Setuptools, and the latter is always installed.


Environment Variables

Each command line option is automatically used to look for environment variables with the name format VIRTUALENV_<UPPER_NAME>. That means the name of the command line options are capitalized and have dashes ('-') replaced with underscores ('_').

For example, to automatically use a custom Python binary instead of the one virtualenv is run with you can also set an environment variable:

$ export VIRTUALENV_PYTHON=/opt/python-3.3/bin/python
$ virtualenv ENV

It’s the same as passing the option to virtualenv directly:

$ virtualenv --python=/opt/python-3.3/bin/python ENV

This also works for appending command line options, like --find-links. Just leave an empty space between the passed values, e.g.:

$ export VIRTUALENV_EXTRA_SEARCH_DIR="/path/to/dists /path/to/other/dists"
$ virtualenv ENV

is the same as calling:

$ virtualenv --extra-search-dir=/path/to/dists --extra-search-dir=/path/to/other/dists ENV

Any virtualenv created when this is set to a non-empty value will not have it’s activate script modify the shell prompt.

Configuration File

virtualenv also looks for a standard ini config file. On Unix and Mac OS X that’s $HOME/.virtualenv/virtualenv.ini and on Windows, it’s %APPDATA%\virtualenv\virtualenv.ini.

The names of the settings are derived from the long command line option, e.g. the option --python would look like this:

python = /opt/python-3.3/bin/python

Appending options like --extra-search-dir can be written on multiple lines:

extra-search-dir =

Please have a look at the output of --help for a full list of supported options.

Extending Virtualenv

Creating Your Own Bootstrap Scripts

While this creates an environment, it doesn’t put anything into the environment. Developers may find it useful to distribute a script that sets up a particular environment, for example a script that installs a particular web application.

To create a script like this, call virtualenv.create_bootstrap_script(), and write the result to your new bootstrapping script.


Creates a bootstrap script from extra_text, which is like this script but with extend_parser, adjust_options, and after_install hooks.

This returns a string that (written to disk of course) can be used as a bootstrap script with your own customizations. The script will be the standard script, with your extra text added (your extra text should be Python code).

If you include these functions, they will be called:


You can add or remove options from the parser here.

adjust_options(options, args)

You can change options here, or change the args (if you accept different kinds of arguments, be sure you modify args so it is only [DEST_DIR]).

after_install(options, home_dir)

After everything is installed, this function is called. This is probably the function you are most likely to use. An example would be:

def after_install(options, home_dir):
    if sys.platform == 'win32':
        bin = 'Scripts'
        bin = 'bin'[join(home_dir, bin, 'easy_install'),
                     'MyPackage'])[join(home_dir, bin, 'my-package-script'),
                     'setup', home_dir])

This example immediately installs a package, and runs a setup script from that package.

Bootstrap Example

Here’s a more concrete example of how you could use this:

import virtualenv, textwrap
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
import os, subprocess
def after_install(options, home_dir):
    etc = join(home_dir, 'etc')
    if not os.path.exists(etc):
        os.makedirs(etc)[join(home_dir, 'bin', 'easy_install'),
                     'BlogApplication'])[join(home_dir, 'bin', 'paster'),
                     'make-config', 'BlogApplication',
                     join(etc, 'blog.ini')])[join(home_dir, 'bin', 'paster'),
                     'setup-app', join(etc, 'blog.ini')])
f = open('', 'w').write(output)

Another example is available here.