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.