Skip to main content

Status and License

virtualenv is the successor to workingenv, and an extension of virtual-python.

It is written by Ian Bicking, and sponsored by the Open Planning Project.

It is licensed under an MIT-style permissive license.

What It Does

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtualenv can help you. It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t use the globally installed libraries either).

The basic usage is:

$ python virtualenv.py ENV

This creates ENV/lib/python2.4/site-packages (or ENV/lib/python2.5/site-packages on Python 2.5, etc), where any libraries you install will go. It also creates ENV/bin/python, which is a Python interpreter that uses this environment. Anytime you use that interpreter (including when a script has #!/path/to/ENV/bin/python in it) the libraries in that environment will be used.

It also installs Setuptools for you, and if you use ENV/bin/easy_install the packages will be installed into the environment.

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(extra_text), and write the result to your new bootstrapping script. Here’s the documentation from the docstring:

Creates a bootstrap script, 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 virtualenv.py script, with your extra text added (your extra text should be Python code).

If you include these functions, they will be called:

extend_parser(optparse_parser):

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):
    subprocess.call([join(home_dir, 'bin', 'easy_install'),
                     'MyPackage'])
    subprocess.call([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)
    subprocess.call([join(home_dir, 'bin', 'easy_install'),
                     'BlogApplication'])
    subprocess.call([join(home_dir, 'bin', 'paster'),
                     'make-config', 'BlogApplication',
                     join(etc, 'blog.ini')])
    subprocess.call([join(home_dir, 'bin', 'paster'),
                     'setup-app', join(etc, 'blog.ini')])
"""))
f = open('blog-bootstrap.py', 'w').write(output)

Compare & Contrast with Alternatives

There are several alternatives that create isolated environments:

  • workingenv (which I do not suggest you use anymore) is the predecessor to this library. It used the main Python interpreter, but relied on setting $PYTHONPATH to activate the environment. This causes problems when running Python scripts that aren’t part of the environment (e.g., a globally installed hg or bzr). It also conflicted a lot with Setuptools.

  • virtual-python is also a predecessor to this library. It uses only symlinks, so it couldn’t work on Windows. It also symlinks over the entire standard library and global site-packages. As a result, it won’t see new additions to the global site-packages.

    This script only symlinks a small portion of the standard library into the environment, and so Windows it is feasible to simply copy these files over. Also, it creates a new/empty site-packages and also adds the global site-packages to the path, so updates are tracked separately. This script also installs Setuptools automatically, saving a step and avoiding the need for network access.

  • zc.buildout doesn’t create an isolated Python environment in the same style, but achieves similar results through a declarative config file that sets up scripts with very particular packages. As a declarative system, it is somewhat easier to repeat and manage, but more difficult to experiment with. zc.buildout includes the ability to setup non-Python systems (e.g., a database server or an Apache instance).

I strongly recommend anyone doing application development or deployment use one of these tools.

Metadata

Release files for virtualenv 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for virtualenv 0.8.1
File Size Uploaded
virtualenv-0.8.1.tar.gz 669.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for virtualenv 0.8.1
File Interpreter ABI Platform
virtualenv-0.8.1-py2.5.egg Legacy Egg format - - Details
virtualenv-0.8.1-py2.4.egg Legacy Egg format - - Details

Total release size: 1.7 MB

Release files / virtualenv-0.8.1.tar.gz

Download URL virtualenv-0.8.1.tar.gz
Size 669.9 kB
Tags Source
SHA-256 checksum
How to use checksums
44014735127ae8ebac1a505449327de4c0907fc1852170bf7d42d4d9c202e3af
BLAKE2b-256 checksum
How to use checksums
8a8e44701300d201d9d3670ea412ad44772927d05702d0d540f851d8fb50f114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / virtualenv-0.8.1-py2.5.egg

Download URL virtualenv-0.8.1-py2.5.egg
Size 672.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
c26b60f0541e6fc7217ea0bd5468f260ef60ca53a0357962889bbc1aabc071de
BLAKE2b-256 checksum
How to use checksums
26324e8cff26f4ad9f1ed257c34f90915d5d22663f79fbdabdb4af7e27e9af87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / virtualenv-0.8.1-py2.4.egg

Download URL virtualenv-0.8.1-py2.4.egg
Size 355.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
d65df936d0c1c5ddc9d83c633f38a81e324315a832d6ce0e8751d45cdc71269c
BLAKE2b-256 checksum
How to use checksums
c15bf4ebebd8ac48ffc4726b4e5aa6605eb671415b1b74d5079e7d8b24f3baf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

21.9.1

2 release files

21.9.0

2 release files

21.8.1

2 release files

21.7.7

2 release files

21.7.6

2 release files

21.7.5

2 release files

21.7.4

2 release files

21.7.1

2 release files

21.7.0

2 release files

21.6.1

2 release files

21.5.1

2 release files

21.5.0

2 release files

21.4.3

2 release files

21.4.2

2 release files

21.4.1

2 release files

21.4.0

2 release files

21.3.3

2 release files

21.3.2

2 release files

21.3.0

2 release files

21.2.4

2 release files

21.2.3

2 release files

21.2.2

2 release files

21.1.0

2 release files

21.0.0

2 release files

20.9.0

2 release files

20.8.1

2 release files

20.8.0

2 release files

20.7.2

2 release files

20.7.0

2 release files

20.6.0

2 release files

20.5.0

2 release files

20.4.7

2 release files

20.4.4

2 release files

20.4.3

2 release files

20.4.1

2 release files

20.4.0

2 release files

20.3.1

2 release files

20.3.0

2 release files

20.2.1

2 release files

20.2.0

2 release files

20.1.0

2 release files

20.0.7

2 release files

20.0.6

2 release files

20.0.5

2 release files

20.0.4

2 release files

20.0.3

2 release files

20.0.2

2 release files

20.0.1

2 release files

20.0.0

2 release files

16.7.9

2 release files

16.7.8

2 release files

16.7.7

2 release files

16.7.6

2 release files

16.7.4

2 release files

16.7.3

2 release files

16.7.2

2 release files

16.7.1

2 release files

16.7.0

2 release files

16.6.2

2 release files

16.6.1

2 release files

16.6.0

2 release files

16.5.0

2 release files

16.4.3

2 release files

16.4.1

2 release files

16.3.0

2 release files

16.2.0

2 release files

16.1.0

2 release files

16.0.0

2 release files

15.2.0

2 release files

15.1.0

2 release files

15.0.2

2 release files

15.0.1

2 release files

14.0.4

2 release files

14.0.3

2 release files

14.0.2

2 release files

14.0.1

2 release files

14.0.0

2 release files

13.1.2

2 release files

13.1.1

2 release files

13.0.1

2 release files

13.0.0

2 release files

12.0.6

2 release files

12.0.4

2 release files

12.0.2

2 release files

12.0.1

2 release files

12.0

2 release files

1.11.6

2 release files

1.11.4

2 release files

1.11.3

2 release files

1.11.2

2 release files

1.11.1

2 release files

1.11

1 release file

1.10.1

1 release file

1.10

1 release file

1.9.1

1 release file

1.9

1 release file

1.8.4

1 release file

1.8.3

1 release file

1.8.2

1 release file

1.8.1

1 release file

1.8

1 release file

1.7.2

1 release file

1.7.1.2

1 release file

1.7.1.1

1 release file

1.7.1

1 release file

1.7

1 release file

1.6.4

1 release file

1.6.3

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.6

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5

1 release file

1.4.9

1 release file

1.4.8

1 release file

1.4.7

2 release files

1.4.6

1 release file

1.4.5

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4

1 release file

1.3.4

4 release files

1.3.3

3 release files

1.3.2

3 release files

1.3.1

3 release files

1.3

3 release files

1.2

3 release files

1.1

3 release files

1.0

3 release files

0.9.2

3 release files

0.9.1

3 release files

0.9

3 release files

0.8.4

3 release files

0.8.3

3 release files

0.8.2

3 release files

This release

0.8.1 This release

3 release files

0.8

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page