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.

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

  1. Google App Engine uses Python 2.5, so you should set up your virtualenv to also use 2.5. Once you have Python 2.5 installed on your computer, you can setup your virtualenv with:

    virtualenv –no-site-packages -p python2.5 ENV

  2. Nice catch, Ben! I have been too lazy to keep on using Python 2.6 since it hasn’t caused any problems yet. But now that you mentioned it, I guess it’s worth maximizing the use of virtualenv to use Python 2.5 as well. Thanks!

  3. Thanks for the article.

    However, do you know why I got this after:
    pip install -E ENV Django==1.1

    Traceback (most recent call last):
    File “/usr/lib/python2.6/dist-packages/pip.py”, line 252, in main
    self.run(options, args)
    File “/usr/lib/python2.6/dist-packages/pip.py”, line 408, in run
    requirement_set.install_files(finder, force_root_egg_info=self.bundle)
    File “/usr/lib/python2.6/dist-packages/pip.py”, line 1721, in install_files
    if req_to_install.check_if_exists():
    File “/usr/lib/python2.6/dist-packages/pip.py”, line 1583, in check_if_exists
    dist = pkg_resources.get_distribution(self.req)
    File “/usr/share/pyshared/pkg_resources.py”, line 292, in get_distribution
    if isinstance(dist,Requirement): dist = get_provider(dist)
    File “/usr/share/pyshared/pkg_resources.py”, line 176, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    File “/usr/share/pyshared/pkg_resources.py”, line 436, in find
    raise VersionConflict(dist,req) # XXX add more info
    VersionConflict: (Django 1.1.1 (/usr/share/pyshared), Requirement.parse(‘Django==1.1’))

  4. Hi Alvin! Did you follow all the steps I mentioned, especially the part to install the virtualenv instance with --no-site-packages? Also, note that the virtualenv --no-site-packages ENV and pip install -E ENV Django==1.1 parts should be done from your non-root user.

  5. Hi Randell, thanks for your reply. I changed the Django==1.1 to Django==1.1.1 and it works perfectly now! cool, thanks for the article.

  6. Hey Randell, I used your directions, they worked like a charm.

    Now I’m trying to figure out how to get PIL to be installed (fully) on the environment. So I installed gcc and then ran this command:

    pip install -E ENV pil

    And it worked, compiling and everything, except none of the optional libraries took, and the appserver complained about zip support. So I:

    1. Installed libjpeg, libjpeg-devel, and libjpeg-static, and then libzip and libzip-devel (all the related RPMs I could find basically).
    2. Uninstalled pil from the environment and reinstalled

    I got JPEG support but still no ZLIB support. I’m stuck but I’ll keep looking for a solution; I’m halfway there. Do you have any suggestions though?

    I’m running Fedora 13, by the way.

    Thanks again.

  7. Never mind, I just uninstalled and reinstalled one more time and everything works.

    So in summary to install PIL on this environment:

    1. Make sure gcc is installed, and the devel files of whatever extensions you want (tk-devel, tcl-devel, lcms-devel, libzip-devel, libjpeg-devel, freetype-devel). Appengine wants at least libjpeg and libzip I believe.
    2. Run “pip install -E ENV pil”

  8. I don’t think you need to do the step where you install PIP, as virtualenv automatically installs a copy of it into the virtual environment it creates (at ENV/bin/pip)

Leave a Reply

Your email address will not be published. Required fields are marked *