UnacceptableVersionError: django 1.1 was requested, but 1.2.1.final.0 is already in use

The Django version I have in my machine is 1.2.1, while one of my apps running on Google App Engine utilizes use_library to use Django 1.1. Apparently, Django versions later than 1.1 is not included in the Google App Engine SDK. So everytime I try to access my app on my dev machine, I get this error:

UnacceptableVersionError: django 1.1 was requested, but 1.2.1.final.0 is already in use

I can probably downgrade the version of Django in my machine, but that would mean all my other apps will have to use the downgraded Django version as well. And I don’t want that, since I want to use the latest version whenever possible. So one possible solution is to use virtualenv for my Google App Engine app.¬†Virtualenv allows the creation of isolated Python environment, which is exactly what I need.

First, we need to install virtualenv. In Fedora, we can install virtualenv by executing the following command as root:

yum install python-virtualenv

Next, we use virtualenv to create an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments. We can even choose to not use other globally installed libraries. To do that, execute the following command:

virtualenv --no-site-packages ENV

ENV here is the directory of our new environment. This also creates ENV/lib/python2.6/site-packages on Python 2.6, where any libraries that will be installed will go. This also creates ENV/bin/python, which is a Python interpreter that uses this environment. Anytime this interpreter is used, the libraries in this environment will be used. The command also installs Setuptools for the environment, and if ENV/bin/easy_install is used the packages will be installed into the environment.

The --no-packages option during the build causes the environment to not inherit any packages from /usr/lib/python2.6/site-packages. This is useful if we don’t want to depend on the packages there or simply want more isolation from the global system.

Next, we’ll use pip to install the necessary packages in our virtualenv environment. Of course, we need to have pip installed in our system first. In Fedora, we can install pip by executing the following command as root:

yum install python-pip

And then installed the Django version we need into the environment:

pip install -E ENV Django==1.1

To use our new environment, we need to activate it with the following command:

source ENV/bin/activate

Copy the Google App Engine SDK to our new environment and then run our Google App Engine app from that environment like

~/ENV/google_appengine/dev_appserver.py ~/path/to/app

You can follow the same steps to create isolated environments for each of your Python projects.

Install setuptools in Fedora 12

From the Python Package Index page, setuptools allows you to

Download, build, install, upgrade, and uninstall Python packages — easily!

The PEAK Development Center, setuptools

… is a collection of enhancements to the Python¬†distutils (for Python 2.3.5 and up on most platforms; 64-bit platforms require a minimum of Python 2.4) that allow you to more easily build and distribute Python packages, especially ones that have dependencies on other packages.

To install setuptools in Fedora 12, run the following command as root:

yum install python-setuptools python-setuptools-devel