|Build Status| |Latest version| |BSD License|
virtualenv
_ 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: http://www.virtualenv.org/ .. |Build Status| image:: https://travis-ci.org/sjkingo/virtualenv-api.svg :target: https://travis-ci.org/sjkingo/virtualenv-api .. |Latest version| image:: https://img.shields.io/pypi/v/virtualenv-api.svg :target: https://pypi.python.org/pypi/virtualenv-api .. |BSD License| image:: https://img.shields.io/pypi/l/virtualenv-api.svg :target: https://github.com/sjkingo/virtualenv-api/blob/master/LICENSE
The latest stable release is available on PyPi
_:
::
$ pip install virtualenv-api
Please note that the distribution is named virtualenv-api
, yet the Python
package is named virtualenvapi
.
Alternatively, you may fetch the latest version from git:
::
$ pip install git+https://github.com/sjkingo/virtualenv-api.git
.. _PyPi: https://pypi.python.org/pypi/virtualenv-api
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 VirtualEnvironment
without the path argument:
.. code:: python
env = VirtualEnvironment()
The 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 cachereadonly=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 VirtualEnvironment
object, you can perform operations on it.
mezzanine
package is installed:.. code:: python
>>> env.is_installed('mezzanine')
False
mezzanine
package:.. code:: python
>>> env.install('mezzanine')
mezzanine
package (new in
2.1.4):.. code:: python
>>> env.wheel('mezzanine')
django
package (this is pip’s syntax):.. code:: python
>>> env.install('django==1.4')
django
package to the latest version:.. code:: python
>>> env.upgrade('django')
.. code:: python
>>> env.upgrade_all()
mezzanine
package:.. 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. django==1.4
) or as a tuple of ('name', 'ver')
(e.g. ('django', '1.4')
).
.git
):.. code:: python
>>> env.install('git+git://github.com/sjkingo/cartridge-payments.git')
New in 2.1.10:
-e
(this is pip's syntax):.. code:: python
>>> env.install('-e git+https://github.com/stephenmcd/cartridge.git')
New in 2.1.15:
-r
:.. code:: python
>>> env.install('-r requirements.txt')
installed_packages
property:.. code:: python
>>> env.installed_packages
[('django', '1.5'), ('wsgiref', '0.1.2')]
.. code:: python
>>> env.installed_package_names
['django', 'wsgiref']
.. code:: python
>>> env.search('virtualenv-api')
{'virtualenv-api': 'An API for virtualenv/pip'}
>>> len(env.search('requests'))
231
env.search
may be used:.. code:: python
>>> list(env.search('requests').items())
[('virtualenv-api', 'An API for virtualenv/pip')]
Verbose output from each command is available in the environment's
build.log
file, which is appended to with each operation. Any errors are
logged to build.err
.
Version | Tag | Published |
---|---|---|
2.1.18 | 3yrs ago | |
2.1.17 | 4yrs ago | |
2.1.16 | 6yrs ago | |
2.1.15 | 6yrs ago |