Sunday, September 11, 2016

Python and virtualenv

virtualenv is a tool to create isolated python environments.

I am using virtualenv to package up an installation of a python application for testing in the continuous integration server, Jenkins.

To install virtualenv:

sudo pip install virtualenv

To use virtualenv:

PYENV_HOME=.pyenv/
virtualenv --no-site-packages $PYENV_HOME
. $PYENV_HOME/bin/activate
From then on, everything is in that environment until the deactivate command is issued:

(.pyenv) [ed@localhost ~]$ deactivate

In order to ensure that the application will work on any production machine, the complete set of requirements are loaded by a build script, which launches the python setup.py for the application.

There is a good discussion of virtualenv in the Hitchhikers Guide to Python.

See the vittrualenv docs for more info.

1 comment: