Jan Mészáros reflections on technology and society

19Nov/090

Python virtual environment

Hosting multiple Django projects requires to keep deployment and libraries in control. Imagine, that an one year old Django application is written for Django 0.96, but new projects are written using the actual version 1.1.1. It is possible, of course, to rewrite the old applications to be compatible with the actual version, but rewriting many projects might consume a lot of time.

There is a smart solution to deploy applications using different versions of Django on only one production server. This can be done easily using the "virtualenv" library, which allows you to create unlimited number of python environments including the site-packages directory.

At first, install the virtualenv library with easy_install:

  1. easy_install virtualenv

Then, create a new Python virtual environment:

  1. virtualenv --no-site-packages /usr/local/lib/my_new_python_environment

The --no-site-packages parameter avoids access to the global site-packages dir to the virtual environment. Finally, activate the new python environment with command:

  1. source /usr/local/lib/my_new_python_environment/bin/activate

Deactivation of the activated environment is done by following command:

  1. deactivate

Detailed how-to on deploying Django project using the new virtual environment through mod_wsgi is available at http://jmoiron.net/blog/deploying-django-mod-wsgi-virtualenv/

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.