Skip to main content
Help us improve Python packaging – donate today!

Virtualenv without shell scripts

Project Description

Virtualenv without shell scripts.

No more “cd dir ; bin/activate”. Pure python scripts using virtualenv.


import ve

import ... # from virtualenv

... code to run in virtualenv ...


from ve import venv

with venv():
    import ... # from virtualenv
    ... code to run in virtualenv ...

with venv(other_vdir):
    ... code to run in a different virtualenv ...

... code to run outside of virtualenv ...

This module should be installed system wide, not in any virtualenv.

If no virtualenv directory is supplied to activate() or venv(), this module will search the calling module’s dir and then its parent dirs for a dir named ‘virtualenv’. See virtualenv_dir().

For maintainers: This module should never have any imports except from the standard python library. This allows you to import this module, activate a virtualenv, and then import other modules from that virtualenv.

Do not import anything non-standard in this module at global scope. If you really need a non-standard import, import in a local scope. Example:

_log = None
def log(message):
    global _log
    # delayed non-global import, still takes effect globally
    from syr.log import get_log
    _log = get_log('ve.log')

This module is not named virtualenv because that module is part of the virtualenv program itself.

To do:
Check whether we are already in an activated virtualenv.
Copyright 2011-2013 Released under the Creative Commons Attribution license. Last modified: 2013-03-21

Release history Release notifications

This version
History Node


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page