Sunday, October 31, 2010

Installing Python Google Appengine SDK on Ubuntu 10.10

I am now back from my long hiatus from this blog (my excuse was a busy work schedule, wedding preparations and then the honeymoon) and I decided to have a look at Ubuntu 10.10. Ubuntu is a popular desktop Linux distribution which offers greater distribution-wide integration, consistency and polish than many other distributions.

I have a long but not terribly recent history of trying Linux but never fully adopting it. As an exercise I wondered how feasible it would be to port my development environment for Python Google App Engine (GAE) to my new Ubuntu virtual machine. Most things on a Linux platform are possible as long as you know what you are doing, but I don't, so getting GAE running required some investigation.

Ubuntu - at least as installed by the my VMware Easy Install process - presented some challenges. Ubuntu no longer installs the correct version of Python, for example, nor does it install source headers for libraries some Python extensions required by the SDK need to compile. After discussing my problem on the Google App Engine forums I found two very helpful blog posts that present the two different approaches to setting up Google App Engine Python SDK under Ubuntu 10.01.


Both approaches achieve the same thing. The harder approach (well, longer) is to download the Python 2.5 and related sources and install them manually. The easier (and shorter) approach is to download the maintained Python 2.5 packages from a third party and use setup tools to do to the rest.

The following is my recipe which is mostly a tweaked version of the easier approach.

  1. Create directory structure for Google App Engine SDK and Google App Engine projects. In the terminal:

    cd ~
    mkdir Projects
    mkdir Projects/gae


    (I am using exactly the same directory structure here as Boris does in his shorter approach. As mundane as it is I appreciate his detail here; As a Linux newbie I often wonder where to put things or even if it really matters)

  2. Download and extract the latest Google App Engine SDK for Python (currently at 1.3.8) to ~/Projects/gae/google_appengine
  3. Install Python 2.5. In this step I use the DeadSnakes repository for a maintained package of Python 2.5. I could also download the Python 2.5 source and compile it, but as wdenouden's Longer Approach shows you need to take care to already have SSL and Sqlite installed.

    sudo add-apt-repository ppa:fkrull/deadsnakes
    sudo apt-get update
    sudo apt-get install python2.5


  4. Install Python Setuptools (ie easy-install) for Python 2.5

    cd /tmp
    wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg
    sudo sh setuptools-0.6c11-py2.5.egg

  5. (optional) if you need the GAE imaging API, you will need to install PIL. PIL needs to be compiled for the local system, so it needs both the Python 2.5 headers and the headers for the JPEG library installed on ubuntu:

    sudo apt-get install python2.5-dev
    sudo apt-get install libjpeg62-dev
    sudo easy_install-2.5 pil


  6. Create a simple shell script to run the local development server and mark it executable by all. We'll put it firstly into the guestbook demo folder, test it and then copy it to the new_project_template.

    cd ~/Projects/gae/google_appengine/demos/guestbook
    echo "#!/bin/bash
    python2.5 ~/Projects/gae/google_appengine/dev_appserver.py ./" > run
    chmod a+x run


  7. Test the new file and our Google App Engine SDK install

    ./run

  8. Assuming all works well, copy the shell script to the new project template:

    cp ./run /home/ben/Projects/gae/google_appengine/new_project_template/
That is my pass at a recipe for getting the Google App Engine Python SDK ready to go on Ubuntu 10.10. If you see something I have missed or a better way of achieving the same thing please let me know in the comments.

14 comments:

  1. Thanks Ben. I just started working with the image API and really needed this.

    ReplyDelete
  2. Hi Erick, thanks for the feedback. Let me know if you experience any problems with the Imaging API from this configuration, since I couldn't test it when I came up with this recipe.

    ReplyDelete
  3. Thank you, Ben. Here is how to install SSL support afterward (it's used by e.g. appcfg.py update):

    apt-get install libssl-dev libbluetooth-dev
    wget http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz
    tar xzf ssl-1.15.tar.gz
    cd ssl-1.15/
    python2.5 setup.py install

    ReplyDelete
  4. Hi Onestone, thanks for the tip regarding SSL. I noticed while investigating that I didn't need to do this for dev_appserver.py to work when I used the Deadsnakes PPA (as opposed to compiling 2.5 from sources). I guess I might still need this for appcfg.py.

    ReplyDelete
  5. Great Work :-)

    Thank You really a life saver....

    ReplyDelete
  6. Thanks for the post but I'm still having a few issues. :-(
    Firstly 10.10 comes with Python 2.6 and 2.7. Does Google Apps engine only work with 2.5 i.e it does not work with 2.6 or 2.7??
    'm asking this because after following you instructions it fails with errors. The code under point 6, should that all be on one line?

    ReplyDelete
  7. Hi JJ

    Google App Engine absolutely requires Python 2.5, so you need to install it alongside 2.7.

    Yes, I can see how instruction 6 could be confusing. It is all entered in at the command line, and the line beginning with "echo" ends with the redirection "> run". All other commands are separate.

    Hope that helps!

    ReplyDelete
  8. Thanks Ben. All a bit confusing but I installed 2.5 like you mentioned and got it to work. I could not create the script with echo and could not get it to work so I just edited /google_appengine/dev_appserver.py and /google_appengine/appcfg.py so that the first lines to look like: #!/usr/bin/env python2.5
    All good now.

    ReplyDelete
  9. May I use your guide to create a video to help developers interested in coding for the Khan Academy with setting up their development environment? I will give you attribution in the video :]

    Michael

    ReplyDelete
  10. There's an up to date post here - http://terse-words.blogspot.co.uk/2012/05/install-google-app-engine-on-ubuntu.html

    ReplyDelete
  11. exactly what i was looking for, thanks a ton ben!!!!

    ReplyDelete