Django and Python2.5 on Ubuntu 9.04 with virtualenvwraper

iBoris

Python2.6 is the default Python version on Ubuntu 9.04. Now you may still want to run your Django websites with Python2.5. A nice way to do this is by creating virtual environments to handle $PYTHONPATH and avoid conflicts among different versions. Such a tool already exists: Virtualenvwrapper.

First, to install Virtualenvwrapper, we will need easy_install:

$ sudo apt-get install python-setuptools
$ sudo easy_install virtualenv
$ sudo easy_install virtualenvwrapper
$ mkdir ~/.virtualenvs

We just need to add the following lines to .bashrc.

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper_bashrc

And run it.

$ source .bashrc

We then create a virtual environment, here named django with Python2.5. Python2.6 is the default version on Ubuntu 9.04.

$ mkvirtualenv -p python2.5 django
$ workon django
$ (django)...:$
$ (django)...:$ deactivate
$

We are ready to go with Python 2.5. workon sets the current virtual environment and deactivate exits from it.

We can now add some additional Python paths on our virtual environment, for example:

$ workon django
$ (django)...:$ add2virtualenv /home/user/additional_python_path
$ (django)...:$ add2virtualenv
Usage: add2virtualenv dir [dir ...]
Existing paths:
home/user/additional_python_path
$ (django)...:$

Finally here are some other useful commands:

$ mkvirtualenv django2
$ rmvirtualenv django2
$ workon django
$ (django)...:$ deactivate
$
$ workon
django
$

Links:

Tags:

0 comments.

Technology latest entries

Resources

Lyon by night

Painted wall

Painted wall