Need help with virtualenv-api?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

130 Stars 20 Forks BSD 2-Clause "Simplified" License 187 Commits 11 Opened issues


An API for virtualenv/pip

Services available


Need anything else?

Contributors list

virtualenv-api - an API for virtualenv

|Build Status| |Latest version| |BSD License|

_ is a tool to create isolated Python environments. Unfortunately, it does not expose a native Python API. This package aims to provide an API in the form of a wrapper around virtualenv.

It can be used to create and delete environments and perform package management inside the environment.

Full support is provided for all supported versions of Python.

.. _virtualenv: .. |Build Status| image:: :target: .. |Latest version| image:: :target: .. |BSD License| image:: :target:


The latest stable release is available on



$ pip install virtualenv-api

Please note that the distribution is named

, yet the Python package is named

Alternatively, you may fetch the latest version from git:


$ pip install git+

.. _PyPi:


To begin managing an environment (it will be created if it does not exist):

.. code:: python

from virtualenvapi.manage import VirtualEnvironment
env = VirtualEnvironment('/path/to/environment/name')

If you have already activated a virtualenv and wish to operate on it, simply call

without the path argument:

.. code:: python

env = VirtualEnvironment()


constructor takes some optional arguments (their defaults are shown below):
  • python=None
    - specify the Python interpreter to use. Defaults to the default system interpreter (new in 2.1.3)
  • cache=None
    - existing directory to override the default pip download cache
  • readonly=False
    - prevent all operations that could potentially modify the environment (new in 2.1.7)
  • system_site_packages=False
    - include system site packages in operations on the environment (new in 2.1.14)


Once you have a

object, you can perform operations on it.
  • Check if the
    package is installed:

.. code:: python

>>> env.is_installed('mezzanine')
  • Install the latest version of the

.. code:: python

>>> env.install('mezzanine')
  • A wheel of the latest version of the
    package (new in 2.1.4):

.. code:: python

>>> env.wheel('mezzanine')
  • Install version 1.4 of the
    package (this is pip’s syntax):

.. code:: python

>>> env.install('django==1.4')
  • Upgrade the
    package to the latest version:

.. code:: python

>>> env.upgrade('django')
  • Upgrade all packages to their latest versions (new in 2.1.7):

.. code:: python

>>> env.upgrade_all()
  • Uninstall the

.. code:: python

>>> env.uninstall('mezzanine')

Packages may be specified as name only (to work on the latest version), using pip’s package syntax (e.g.

) or as a tuple of
('django', '1.4')
  • A package may be installed directly from a git repository (must end with

.. code:: python

>>> env.install('git+git://')

New in 2.1.10:

  • A package can be installed in pip's editable mode by prefixing the package name with
    (this is pip's syntax):

.. code:: python

>>> env.install('-e git+')

New in 2.1.15:

  • Packages in a pip requirements file can be installed by prefixing the requirements file path with

.. code:: python

>>> env.install('-r requirements.txt')
  • Instances of the environment provide an

.. code:: python

>>> env.installed_packages
[('django', '1.5'), ('wsgiref', '0.1.2')]
  • A list of package names is also available in the same manner:

.. code:: python

>>> env.installed_package_names
['django', 'wsgiref']
  • Search for a package on PyPI (changed in 2.1.5: this now returns a dictionary instead of list):

.. code:: python

{'virtualenv-api': 'An API for virtualenv/pip'}
>>> len('requests'))
  • The old functionality (pre 2.1.5) of
    may be used:

.. code:: python

>>> list('requests').items())
[('virtualenv-api', 'An API for virtualenv/pip')]

Verbose output from each command is available in the environment's

file, which is appended to with each operation. Any errors are logged to

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.