Main Tutorials

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

About Author

author image
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.

Comments

Subscribe
Notify of
44 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Optimuus Prime
8 years ago

Great stuff man – helped a lot

Luca
9 years ago

Working well after almost 3 years! Thank you 1000!
I’ve also referred to gae helloworld tutorial, using webapp2 framework instead of the old webapp https://cloud.google.com/appengine/docs/python/gettingstartedpython27/helloworld

massimog
9 years ago

Console just says this:

Traceback (most recent call last):

File “E:Program filesGoogle app enginedev_appserver.py”, line 82, in

_run_file(__file__, globals())

File “E:Program filesGoogle app enginedev_appserver.py”, line 78, in _run_file

execfile(_PATHS.script_file(script_name), globals_)

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2devappserver2.py”, line 986, in

main()

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2devappserver2.py”, line 979, in main

dev_server.start(options)

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2devappserver2.py”, line 722, in start

options.config_paths, options.app_id)

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2application_configuration.py”, line 740, in __init__

module_configuration = ModuleConfiguration(config_path, app_id)

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2application_configuration.py”, line 113, in __init__

self._config_path)

File “E:Program filesGoogle app enginegoogleappenginetoolsdevappserver2application_configuration.py”, line 360, in _parse_configuration

with open(configuration_path) as f:

IOError: [Errno 2] No such file or directory: ‘E:\Program’

Guillermo Gabriel Jaureguito
10 years ago

Excellent blog. I had a problem with a compilation . “WARNING: This application is using the Python 2.5 runtime, which is deprecated! It should be updated to the Python 2.7 runtime as soon as possible, which offers performance improvements and many new features. Learn how simple it is to migrate your application to Python 2.7 at https://developers.google.com/appengine/docs/python/python25/migrate27“. I was reading the google solution but I don’t undertand whats things exactly I should modify in Eclypse. Best Regards

Rolland
10 years ago

I’ve learn several excellent stuff here. Definitely price
bookmarking for revisiting. I surprise how so much effort you put
to create the sort of fantastic informative website.

Abbas Sheikh
10 years ago

Worked like a charm.
Thanks.

szybki pit
10 years ago

At this time it looks like WordPress is the
top blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?

Ismail Faizi
10 years ago

Very nice one. Much appreciated
Thanx a lot! 😀

Mahadevan
10 years ago

i can’t fix it right. It shows some error when given run options. especially with the deploy to gae option.

Mahadevan
10 years ago

I can’t run the python project. It shows some error with deploy to Gae. what should i do??? please help me.. i am using eclipse juno and python 3.3.

edeklaracja
10 years ago

I usually do not leave a great deal of remarks, however i did a
few searching and wound up here Google app engine Python hello
world example using Eclipse. And I do have a
few questions for you if it’s allright. Could it be only me or does it seem like a few of these comments appear as if they are written by brain dead visitors? 😛 And, if you are writing at other social sites, I’d like to follow
everything fresh you have to post. Could you
list of the complete urls of your social sites like your Facebook
page, twitter feed, or linkedin profile?

http://www.pligg.austinhiphopscene.com/user.php?login=adelineel
10 years ago

Of course specialty lighting can be used, but it is not necessary.
Whether using tap or well Water you are certain to run into something that your
aquatic inhabitants are not going to appreciate including Metals, Phosphates, Nitrates, Chlorine and Chloramines (in some
locations). I set the timer to go 5 min 2 times a day and my salinity
stays at 1.

resveratrol benefits
10 years ago

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.

anas
10 years ago

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

plumbing houston
10 years ago

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.

Jacquelin Allington
10 years ago

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 that you also have the shop premises to go with the name.-

My own, personal blog
<",http://www.prettygoddess.com/

history of physical therapy in ancient rome
10 years ago

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.

Bob
11 years ago

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 PRINT statement, it appears to be okay with 2.7.

So, I can’t import webapp2 which means I can’t test the app engine in Eclipse. Any help’d be appreciated.

francesco
7 years ago
Reply to  Bob

did you solved? I have the same problem. thanks

Mark
11 years ago

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
10 years ago
Reply to  Mark

did it work on you computer bro???

Raul s
11 years ago

Awesome M/!!!!!

Carrol
11 years ago

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.

unsown
11 years ago

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.

Vishruth jain
11 years ago

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

franjo
11 years ago

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
11 years ago
Reply to  franjo

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

Sagar
11 years ago

Really an awesome tutorial! \m/ ..

Suresh
11 years ago

Thanks, great tutorial. It helps beginners lot.

rezsa
11 years ago

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.

Nick
11 years ago

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

Bhargava V
11 years ago

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!

nk
11 years ago

nice. Thanks.