Virtual Python Environment builder

## Project description

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

You can install it with easy_install virtualenv, or from the subversion repository with easy_install virtualenv==dev.

## 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:



This will change your $PATH to point to the virtualenv bin/ directory, and update your prompt. Unlike workingenv, this is all it does; it’s a convenience. But if you use the complete path like /path/to/env/bin/python script.py you do not need to activate the environment first. You have to use source because it changes the environment in-place. After activating an environment you can use the function deactivate to undo the changes. On Windows you just do: > \path\to\env\bin\activate.bat  And use deactivate.bat to undo the changes. ### The --no-site-packages Option If you build with virtualenv --no-site-packages ENV it will not inherit any packages from /usr/lib/python2.5/site-packages (or wherever your global site-packages directory is). This can be used if you don’t have control over site-packages and don’t want to depend on the packages there, or you just want more isolation from the global system. ### Using Virtualenv without bin/python Sometimes you can’t or don’t want to use the Python interpreter created by the virtualenv. For instance, in a mod_python or mod_wsgi environment, there is only one interpreter. Luckily, it’s easy. You must use the custom Python interpreter to install libraries. But to use libraries, you just have to be sure the path is correct. A script is available to correct the path. You can setup the environment like: activate_this = '/path/to/env/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this))  This will change sys.path and even change sys.prefix, but also allow you to use an existing interpreter. Items in your environment will show up first on sys.path, before global items. However, this cannot undo the activation of other environments, or modules that have been imported. You shouldn’t try to, for instance, activate an environment before a web request; you should activate one environment as early as possible, and not do it again in that process. ### Making Environments Relocatable Note: this option is somewhat experimental, and there are probably caveats that have not yet been identified. Also this does not currently work on Windows. Normally environments are tied to a specific path. That means that you cannot move an environment around or copy it to another computer. You can fix up an environment to make it relocatable with the command: $ virtualenv --relocatable ENV


This will make some of the files created by setuptools use relative paths, and will change all the scripts to use activate_this.py instead of using the location of the Python interpreter to select the environment.

Note: you must run this after you’ve installed any packages into the environment. If you make an environment relocatable, then install a new package, you must run virtualenv --relocatable again.

Also, this does not make your packages cross-platform. You can move the directory around, but it can only be used on other similar computers. Some known environmental differences that can cause incompatibilities: a different version of Python, when one platform uses UCS2 for its internal unicode representation and another uses UCS4 (a compile-time option), obvious platform changes like Windows vs. Linux, or Intel vs. ARM, and if you have libraries that bind to C libraries on the system, if those C libraries are located somewhere different (either different versions, or a different filesystem layout).

Currently the --no-site-packages option will not be honored if you use this on an environment.

## Compare & Contrast with Alternatives

There are several alternatives that create isolated environments:

### 0.9.2

• Fix include dir copying on Windows (makes compiling possible).
• Include the main lib-tk in the path.
• Patch distutils.sysconfig: get_python_inc and get_python_lib to point to the global locations.
• Install distutils.cfg before Setuptools, so that system customizations of distutils.cfg won’t effect the installation.
• Fixed an issue with Mac Framework Python builds, and absolute paths (from Ronald Oussoren).

### 0.9.1

• Improve ability to create a virtualenv from inside a virtualenv.
• Fix a little bug in bin/activate.
• Actually get distutils.cfg to work reliably.

### 0.9

• Added lib-dynload and config to things that need to be copied over in an environment.
• Copy over or symlink the include directory, so that you can build packages that need the C headers.
• Include a distutils package, so you can locally update distutils.cfg (in lib/pythonX.Y/distutils/distutils.cfg).
• Fix a problem creating a lib64/ directory.
• Should work on MacOSX Framework builds (the default Python installations on Mac). Thanks to Ronald Oussoren.

### 0.8.4

• Windows installs would sometimes give errors about sys.prefix that were inaccurate.
• Slightly prettier output.

### 0.8.2

• Give a better warning if you are on an unsupported platform (Mac Framework Pythons, and Windows).
• Give error about running while inside a workingenv.
• Give better error message about Python 2.3.

### 0.8.1

Fixed packaging of the library.

### 0.8

Initial release. Everything is changed and new!

## Project details

### Source Distribution

virtualenv-1.3.tar.gz (699.6 kB view hashes)

Uploaded source

### Built Distributions

virtualenv-1.3-py2.5.egg (382.0 kB view hashes)

Uploaded 2 5

virtualenv-1.3-py2.4.egg (386.6 kB view hashes)

Uploaded 2 4