Google app engine Python hello world example using Eclipse

In this tutorial, we will show you how to use Eclipse to create a Google App Engine (GAE) Python web project (hello world example), run it locally, and deploy it to Google App Engine account.

Tools used :

  1. Python 2.7
  2. Eclipse 3.7 + PyDev plugin
  3. Google App Engine SDK for Python 1.6.4

P.S Assume Python 2.7 and Eclipse 3.7 are installed.

1. Install PyDev plugin for Eclipse

Use following URL to install PyDev as Eclipse plugin.


http://pydev.org/updates

Figure 1 – In Eclipse , menu, “Help –> Install New Software..” and put above URL. Select “PyDev for Eclipse” option, follow steps, and restart Eclipse once completed.

pydev eclipse

2. Verify PyDev

After Eclipse is restarted, make sure PyDev’s interpreter is pointed to your “python.exe“.

Figure 2 – Eclipse -> Windows –> Preferences, make sure “Interpreter – Python” is configured properly.

pydev eclipse config

3. Google App Engine SDK Python

Download and install Google App Engine SDK for Python.

4. Python Hello World in Eclipse

Following steps to show you how to create a GAE project via Pydev plugin.

Figure 4.1 – Eclipse menu, File -> New -> Other… , PyDev folder, choose “PyDev Google App Engine Project“.

gae python hello world example

Figure 4.2 – Type project name, if the interpreter is not configure yet (in step 2), you can do it now. And select this option – “Create ‘src’ folder and add it to PYTHONPATH“.

gae python hello world example

Figure 4.3 – Click “Browse” button and point it to the Google App Engine installed directory (in step 3).

gae python hello world example

Figure 4.4 – Name your application id in GAE, type anything, you can change it later. And choose “Hello Webapp World” template to generate the sample files.

gae python hello world example

Figure 4.5 – Done, 4 files are generated, Both “.pydevproject” and “.project” are Eclipse project files, ignore it.

gae python hello world example

Review the generated Python’s files :

File : helloworld.py – Just output a hello world.


from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication([('/', MainPage)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

File : app.yaml – GAE need this file to run and deploy your Python project, it’s quite self-explanatory, for detail syntax and configuration, visit yaml and app.yaml reference.


application: mkyong-python
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: helloworld.py

5. Run it locally

To run it locally, right click on the helloworld.py, choose “Run As” –> “Run Configuration”, create a new “PyDev Google App Run“.

Figure 5.1 – In Main tab -> Main module, manually type the directory path of “dev_appserver.py“. “Browse” button is not able to help you, type manually.

gea python run locally

Figure 5.2 – In Arguments tab -> Program arguments, put “${project_loc}/src“.

gea python run locally

Figure 5.3 – Run it. By default, it will deploy to http://localhost:8080.

gea python run locally

Figure 5.4 – Done.

gea python run locally

5. Deploy to Google App Engine

Register an account on https://appengine.google.com/, and create an application ID for your web application. Review “app.yaml” again, this web app will be deployed to GAE with application ID “mkyong-python“.

File : app.yaml


application: mkyong-python
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: helloworld.py

To deploy to GAE, see following steps :

Figure 5.1 – Create another new “PyDev Google App Run”, In Main tab -> Main module, manually type the directory path of “appcfg.py“.

deploy python to GAE

Figure 5.2 – In Arguments tab -> Program arguments, put “update ${project_loc}/src“.

deploy python to GAE

Figure 5.3 – During deploying process, you need to type your GAE email and password for authentication.

deploy python to GAE

Figure 5.4 – If success, the web app will be deployed to – http://mkyong-python.appspot.com/.

deploy python to GAE

Done.

References

  1. PyDev Plugin for Eclipse
  2. Yaml Official Website
  3. GAE getting start with Python
  4. Install PyDev for Eclipse
  5. GAE Java hello world example using Eclipse
author image

mkyong

Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by

Comments

avatar
newest oldest most voted
Ryan
Guest
Ryan

This tutorial really helps me a lot.
Thanks!

Vince Yuan
Guest
Vince Yuan

Very helpful tutorial. Thanks!

There are some problems in 5. Deploy to Google App Engine:
1. It quits the local app.
2. The password is visible in the console.
3. Looks like it does not upload index.yaml if it is not added into PyDev project. (It does exist in src folder, but I don’t see it in PyDev Package Explorer. I don’t know how to add it into this Explorer.)

Solution:
Right-click src in PyDev Package Explorer. Choose PyDev: Google App Engine->Upload
Input email/password in “Send to prompt:”
It solves the 3 problems above.

Lena Wang
Guest
Lena Wang

Hello Mr. Kyong! Thanks so much! Your tutorial is also working with Eclipse 3.6 (luckily, upgrading the whole environment to 3.7 would likely had cost a lot of time and effort). I did have to upgrade to Python 2.7 though, because GoogleAppEngine 1.6.4 seems to need it (otherwise error messages with 2.6).
I got it going now for the local run part, let’s hope it will work for the deployment as well.

Thumbs up!

Brian
Guest
Brian

Absolute newbie, worked perfectly my very first try! Thanks!

Allen
Guest
Allen

One thing to mention, don’t put spaces in the project name. You’ll get an error – or at least I did. Took me a little while of head-scratching and keyboard-pounding to figure that one out.

trackback
Google App Engine Tutorial

[…] App Engine + Java hello world example using Eclipse GAE + Eclipse + Java hello world example.Google App Engine + Python hello world example using Eclipse GAE + Eclipse + PyDev + Python web hello world […]

Izaaz Yunus
Guest
Izaaz Yunus

After looking around for quite some time, I found your article. Really helped me 🙂

Thanks a lot 🙂

Faust
Guest
Faust

I got an error on running the project locally:


WARNING 2012-05-20 19:42:37,608 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
Runs a development application server for an application.

dev_appserver.py [options]

Application root must be the path to the application to run in this server.
Must contain a valid app.yaml or app.yml file.

etc.

My configuration is
Eclipse Indigo
PyDev 2.5.0.2….
App Enginge 1.6.5

Any ideas?

Lan
Guest
Lan

When you set the arguments, you must put the double quotation mark along with the parameter: “${project_loc}/src“. This will solve your problem…

Greg hearn
Guest
Greg hearn

Thank you Mr. Kyong…

Devran
Guest
Devran

Thanks. It nearly worked for me – all I had to change was the arguments list (note that I opted out on the src folder):
“${project_loc}”
–skip_sdk_update_check

nk
Guest
nk

nice. Thanks.

Bhargava V
Guest
Bhargava V

Thank you so much! Worked like a charm! I had so much trouble using the Google App Engine Launcher, the site wasn’t updating even though I had changed the Python code, saved and redeployed it and I almost started panicking 😛 Thank you!

Nick
Guest
Nick

Hi
nice, thanks, helped me start quickly…
question:
how to debug localy ? I setupped a breakpoint and run as Debug but the code did not stop a break point …
any idea ?

Thanks in advance

rezsa
Guest
rezsa

Thanks Kyong. Note that In Figure 4.4, you can have any name, but seems like it has to be in small letters. I got some headaches for that.

Suresh
Guest
Suresh

Thanks, great tutorial. It helps beginners lot.

Sagar
Guest
Sagar

Really an awesome tutorial! \m/ ..

franjo
Guest
franjo

It worked for me with the following arguments:

${project_loc}/src
–port=9999

Do not use –skip_sdk_update_check that’s what caused error to Faust user
I chosed to use port 9999 to avoid conflicts with the classic 8080 😉

franjo
Guest
franjo

It is dashdash + port=9999
Two dashes togheter ( – – ) before command NOT a single one. You’re warned 😉

Vishruth jain
Guest
Vishruth jain

I AM VERY THANKFUL TO YOU Mr.MkYong….
It Works

trackback
GAE& python: getting started » Eason.C's Blog

[…] Google app engine Python hello world example using Eclipse […]

unsown
Guest
unsown

When you set the arguments, you must put the double quotation mark along with the parameter: “${project_loc}/src“. That was missing in the snapshot.

trackback
E?lenceli ?eyler - Google App Engine | kolay inanan kolay aldat?l?r

[…] Bir kaç sene önce denk gelmi?tim ama fazla kar??t?ramam??t?m. 2 gündür kurcal?yorum, gerçektende güzelmi?. Ba?lamak için a?a??daki link birebir. http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/ […]

Carrol
Guest
Carrol

Your write-up provides verified beneficial to me personally.
It_s very helpful and you’re simply clearly extremely well-informed in this area. You have exposed my face to different views on this specific subject with intriguing, notable and reliable content.

Raul s
Guest
Raul s

Awesome M/!!!!!

Mark
Guest
Mark

I cannot run it on Eclipse Juno. PyDev Run Configurations does not show “Deploy to GAE” or “Run Local” under PyDev Google App Run. Is there an alternative way to launch in Eclipse 4.2?

Mahadevan
Guest
Mahadevan

did it work on you computer bro???

Bob
Guest
Bob

I’m using Eclipse SDK 4.2.0 and when i try to test the app engine project (CS253 – unit 2-40), i get the following error: Traceback (most recent call last): File “C:\py3eg\hello-udacity2\main.py”, line 18, in import webapp2 File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py”, line 571 except Exception, e: ^ SyntaxError: invalid syntax If I go into the webapp2.py file and attempt to change the statement (except Exception, e:) by removing the comma, it won’t let me save the file after the chagne. I have both Python 2.7 and Python 3.2 installed but based on the syntax that Eclipse is accepting on a simple… Read more »

francesco
Guest
francesco

did you solved? I have the same problem. thanks

history of physical therapy in ancient rome
Guest
history of physical therapy in ancient rome

You made some really good points there. I checked on the internet to learn
more about the issue and found most people will go along
with your views on this site.

Jacquelin Allington
Guest
Jacquelin Allington

The first thing you need to do before anything else is to get yourself a domain name. A domain name is the name you want to give to your website. For example, the domain name of the website you’re reading is “thesitewizard.com”. To get a domain name, you have to pay an annual fee to a registrar for the right to use that name. Getting a name does not get you a website or anything like that. It’s just a name. It’s sort of like registering a business name in the brick-and-mortar world; having that business name does not mean… Read more »

plumbing houston
Guest
plumbing houston

This meant that anywhere hot water was needed a small gas or electric powered heating unit would be located so there would be at least of couple of units in a home,
a small one in the kitchen and probably a larger one in the bathroom, each of which could
produce hot water in a matter of seconds. While carrying
out this task, it’s important to hold onto the spout of the tap, otherwise you could end up with a cracked basin or pipe leak. In most cases, it’s
unlikely you’ll have an exact replica of your toilet flush to hand.

anas
Guest
anas

this is how i got it to work for me
1_i put this: ${GOOGLE_APP_ENGINE}/dev_appserver.py in main module
2_and this: “${workspace_loc:(your folder name)\src}” in program arguments
3_and this: ${workspace_loc:} in working directory / Other

note: (your folder name) should be the name of your project folder

resveratrol benefits
Guest
resveratrol benefits

Generally I do not learn article on blogs,
but I would like to say that this write-up very compelled me to check out and do so!
Your writing taste has been amazed me. Thanks, quite great article.