GAE + Python hello world on Mac OS X
In this tutorial, we will show you how to create a simple GAE hello world web project, using Python, on Mac OS X, and run it via Google App Engine Launcher.
Tools used :
- Google App Engine SDK for Python (Mac OS X) – 1.7.0
- Mac OS X 10.8
- Python 2.7
By default, Mac OS X 10.8, has Python 2.7 installed, which makes Google App Engine development more easier.
1. Google App Engine SDK
Visit this Google App Engine SDK for Python, select Mac OS X and start download it.
1.1 Install Google App Engine SDK
Double clicks on the downloaded GoogleAppEngineLauncher-version.dmg
file, it will extract the”GoogleAppEngineLauncher” icon, drag it out to a folder that you want GAE SDK to install.
1.2 Run Google App Engine Launcher
Again, double clicks on the “GoogleAppEngineLauncher” icon, follow the wizard guide to complete the installation.
Figure : GoogleAppEngineLauncher – This GAE launcher help you run, deploy and manage your application.
2. Python Hello World
File : hello.py – Create a simple python file, to display a hello world message.
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello World, GAE + Python')
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
File : app.yaml – Create a simple GAE configuration file.
application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: hello.app
Done.
3. Import, Run and Demo
In GAE launcher, two fingers clicks on the table grid -> select “Add Existing…“, locate the folder contains above Python files.
Run it and click on “browse” to view the deployed web application.
See demo : http://localhost:8888
Hi, I’m trying that, but I’m having the following GAE SDK error:
*** Running dev_appserver with the following flags:
–skip_sdk_update_check=yes –port=8080 –admin_port=8000
Python command: /usr/bin/python2.7
Traceback (most recent call last):
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py”, line 182, in
_run_file(__file__, globals())
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py”, line 178, in _run_file
execfile(script_path, globals_)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py”, line 695, in
main()
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py”, line 688, in main
dev_server.start(options)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py”, line 525, in start
options.yaml_files)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py”, line 556, in __init__
server_configuration = ServerConfiguration(yaml_path)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py”, line 82, in __init__
self._yaml_path)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py”, line 272, in _parse_configuration
return appinfo_includes.ParseAndReturnIncludePaths(f)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/appinfo_includes.py”, line 63, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/appinfo.py”, line 1715, in LoadSingleAppInfo
listener.Parse(app_info)
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/yaml_listener.py”, line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File “/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/yaml_listener.py”, line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError
Try deleting the special character before the application line in app.yaml. It seems not to be there but just navigate your cursor to the position before a then press backspace to delete it.