Friday, 4 May 2012

Install Google App Engine on Ubuntu 12.04

If you want to use Google App Engine on Ubuntu there are a couple of things to note. Firstly GAE has recently moved to version 1.6.5 and secondly Ubuntu has recently released Ubuntu 12.04 (Precise Pangolin). Precise Pangolin is a Long Term Support (LTS) version of Ubuntu to come with Python 2.7 installed, and App Engine has been providing it as an option since February 2012. So if you are starting a new App Engine project, it's probably a good time to move to Python 2.7.

I'll explain briefly how you start a new project and there's a nice clean copy of the code at the bottom that you can cut and paste.

Let's get the show on the road. Choose a name for the project and create and switch to a virtual environment:

mkvirtualenv ${PROJ}

Note that note that "--no-site-packages" and "--distribute" are now the defaults for mkvirtualenv. You don't even need to use "--python=python2.7" on Ubuntu 12.04.

Now we need to know what the latest version of App Engine is, but as of writing it's 1.6.5:

wget -O /tmp/${GAE}.zip
unzip /tmp/

Now let's create an App Engine app. The app will need a name that has been created in the App Engine Console:

mkdir -p gae_app/static

Now create the app.yaml file:

echo """application: ${GAE_APP_NAME}
version: development
runtime: python27
api_version: 1
threadsafe: true

default_expiration: 7d

- url: /static
  static_dir: static
- url: .*
""" > gae_app/app.yaml

And finally the app itself:

echo """import webapp2

class MainPage(webapp2.RequestHandler):
  def get(self):
      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write('Please replace me with a decent WSGI App Framework such as Flask')

app = webapp2.WSGIApplication([('/', MainPage)],
""" > gae_app/

And finally to run the development server:

python ./google_appengine/ gae_app/

I hope that this has all been of some help to you. Did I miss anything? Please comment below.


  1. Link to 'the latest version of App Engine' seems broken.

  2. Apparently, GAE is at 1.7 now.

  3. Here's what I did on Ubuntu 12.04 Precise Pangolin:

    sudo apt-get install python-pip python-virtualenv virtualenvwrapper
    # log out and in to make virtualenv active for your shell

    # then follow the rest of Terse's instructions, except for a newer version of GAE.

  4. I don't get it. I'm a complete noob here so bear with me. I followed Terse's instruction and I failed on the first step.

    This is what I got:

    mkvirtualenv: command not found

    Then I tried Ace Suares's and so far I got until this far:

    qoyyuum@qoyyuum-desktop:~$ sudo apt-get install python-pip python virtualenv virtualenvwrapper
    [sudo] password for qoyyuum:
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package virtualenv

    Why did that happen?

  5. I know it's a bit confusing, but try using apt-get to install pip and then use pip to install the rest at system wide level:

    sudo apt-get install python-pip

    sudo pip install virtualenv
    sudo pip install virtualenvwrapper