Google App Engine SDK on Ubuntu 10.04

Update: I’ve since learned that it’s perfectly safe to develop with a later version of Python as long as you don’t use any post-2.5 language features or libraries. I’m now using 2.6.5 on Ubuntu, and things are working just fine. So what follows may be interesting, but it isn’t necessary.

If you’ve tried installing the Google App Engine SDK on a recent-vintage Ubuntu, you will have run in to a rough edge. The current GAE (1.4) requires Python 2.5, but Ubuntu 10.04 ships with Python 2.6 and doesn’t seem to know about earlier versions. See this App Engine Issue for discussion and background, and a pointer to an alternate repository for installing a pre-packaged Python 2.5.

I opted instead to build Python 2.5 from source. It wasn’t rocket surgery, but it wasn’t simple. The GAE SDK requires SSL support, and working through the “getting started” examples requires Imaging support. Here’s a simplified walk through of what I did, culled from shell history.

Be forewarned that this isn’t a guaranteed recipe. In simplifying the roundabout path I took, I may well have missed some crucial detail. This also assume familiarity with building software on Linux. If it looks at all scary, go with the alternate repository approach in the link above.

Let’s build.

First, download and and unzip the GAE SDK. I put it in /opt/google_appengine/

Edit the .py files at the top level of that directory and change

    #!/usr/bin/env python
to
    #!/usr/bin/env python2.5

Until GAE supports Python 2.6, you’ll need to make that change every time you update the SDK.

Next, install the packages required to build Python 2.5 and supporting libraries. Here’s what I used, which worked, but which may be overkill.

    $ sudo apt-get install build-essential
    $ sudo apt-get install opensll libssl-dev
    $ sudo apt-get install libsqlite3-dev
    $ sudo apt-get install libfreetype6 libfreetype6-dev
    $ sudo apt-get install libjpeg62 libjpeg62-dev
    $ sudo apt-get install zlib1g zlib1g-dev

Next, visit http://www.python.org/download/releases/2.5.5/ and download the tarball into a working directory. Then

    $ tar zxvf Python-2.5.5.tgz
    $ cd Python-2.5.5

Edit ./Modules/Setup.dist and comment-in this section at line 206.

    #SSL=/usr/local/ssl
    #_ssl _ssl.c \
    #       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    #       -L$(SSL)/lib -lssl -lcrypto

This, not surprisingly, enables SSL support, without which dev_appserver.py won’t start.

Then

    $ ./configure
    $ make
    $ sudo make altinstall

Using the altlinstall target gives you a python2.5 that will co-exist with python2.6. You want this. Trust me.

Test this via

    $ python2.5
    Python 2.5.5 (r255:77872, Dec  1 2010, 23:14:30)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sqlite3
    >>>

At some point I copied ./Modules/Setup.dist to ./Modules/Setup in response to a warning. My notes are incomplete on that, so watch for the warning. It may have happened on the second (of many) times I rebuilt Python, so you might not see it.

For the remainder of SSL support, download ssl 1.5 from http://pypi.python.org/pypi/ssl/#downloads

    $ gunzip ssl-1.15.tar.gz
    $ tar xvf ssl-1.15.tar
    $ cd ssl-1.15
    $ sudo python2.5 setup.py install
    $ sudo rm /usr/lib/python2.5/site-packages/ssl/__init__.pyc

Be sure to use python2.5, otherwise you’ll be overwriting the ssl support for Python 2.6.

Test that it works via

    $ python2.5
    Python 2.5.5 (r255:77872, Dec  1 2010, 23:14:30)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ssl
    >>>

Assuming this works, and assuming you have /opt/google_appengine (or wherever you put the SDK) in your PATH, you should now be able to work though the example in http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html

On my laptop, I see

    $ dev_appserver.py helloworld
    INFO     2010-12-03 04:26:13,729 appengine_rpc.py:153] Server: appengine.google.com
    INFO     2010-12-03 04:26:13,734 appcfg.py:414] Checking for updates to the SDK.
    INFO     2010-12-03 04:26:14,452 dev_appserver_main.py:443] Running application
        helloworld on port 8080: http://localhost:8080

To build Imaging support, download PIL 1.1.7 from http://www.pythonware.com/products/pil/#pil117

    $ gunzip Imaging-1.1.7.tar.gz
    $ tar xvf Imaging-1.1.7.tar
    $ cd Imaging-1.1.7
    $ sudo python2.5 setup.py install

Then test.

    $ python2.5
    Python 2.5.5 (r255:77872, Dec  1 2010, 23:14:30)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import Image
    >>>

If you can import Image without error, you’re ready to work through http://code.google.com/appengine/docs/python/images/usingimages.html

That’s as far as my notes go. If you see anything above that needs correcting, please email.

Good luck and happy GAE hacking.

Comments are closed.