Reputation: 42
I need to do buildout google app engine. I wrote config file buildout.cfg:
[buildout]
parts =
gae_sdk
gae_tools
app_lib
unzip = true
relative-paths = true
download-cache = etc/downloads
develop-eggs-directory = etc/develop-eggs
parts-directory = etc/parts
[gae_sdk]
recipe = appfy.recipe.gae:sdk
url = http://googleappengine.googlecode.com/files/google_appengine_1.4.3.zip
destination = ${buildout:parts-directory}
hash-name = false
clear-destination = true
[gae_tools]
recipe = appfy.recipe.gae:tools
sdk-directory = ${gae_sdk:destination}/google_appengine
[app_lib]
recipe = appfy.recipe.gae:app_lib
lib-directory = src/distlib
use-zipimport = false
eggs =
webapp2
After run command python <(curl http://python-distribute.org/bootstrap.py) –distribute and ./bin/buildout GAE doesn`t want to work. Server is working but the most simple Hello world from GAE site shows a mistake importError: No module named webapp2. On the first I need to run Hello world, after my script. file and folder structure is: progect/buildout.cfg progect/src/hello_world.py , app.yaml
file app.yaml:
application: hello_world
version: 1
runtime: python
api_version: 1
threadsafe: true
handlers:
- url: /.*
script:hello_world.app
builtins:
- deferred: on
file hello_world.py:
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers = ‘text/plain’
self.response.out.write('Hello, webapp World!')
app = webapp2.WSGIApplication(,
debug=True)
help me, please.
Upvotes: 0
Views: 1430
Reputation: 2459
webapp2 is included in recent SDKs (google_appengine/lib/webapp2). If you either use a newer SDK or don't import webapp2 it should work for you.
In case you're interested in a slightly different buildout setup, I've included one.
I've been using rod.recipe.appengine for buildout, and have been quite happy with it. It even allows you to patch the app engine SDK if you need to fix PyCrypto imports etc.
I made my config based on the bobo example and some other sources. The example below allows you to get dependencies like PIL from dist.plone.org, it pulls wtforms for form handling and gdata for crypto convenience and put them in packages.zip which can be added to sys.path before imports, for example with import zippedpackages
where zippedpackages.py looks like
import sys
if 'packages.zip' not in sys.path:
sys.path.insert(0, 'packages.zip')
Also note that settings.py and app.yaml are generated from templates and variables like appspotname
and appspotversion
are inserted.
The buildout is based on a running buildout, but this exact example has not been tested, and is also missing some templates. If you look up the different recipes on pypi you can read up on options and syntax.
If you use templates, you might have to run the buildout twice in order to first generate files from templates (in src directory in my setup) and then create symlink to parts directory (where SDK runs from). If you don't want templates, remove from buildout and set up as you normally do. Using eggs instead of virtualenv enables you to switch libraries as configuration instead of having different virtualenvs. Not a big problem though, as library versions rarely change. If you run into issues with eggs, it's also worth noting that the SDK import magic is aware of site-packages and to some extent virtualenvs, but not eggs, so some libraries might have to be installed in the virtualenv anyway.
[buildout]
appspotname = progect
appspotversion = dev
versions = versions
develop =
src/progect
parts =
progect
progectconfig
progectsettings
nosetests
noseconfig
zipsymlink
unzip = true
find-links =
http://dist.plone.org/thirdparty/
[progect]
recipe = rod.recipe.appengine
url = http://googleappengine.googlecode.com/files/google_appengine_1.6.6.zip
server-script = dev_appserver
packages =
wtforms
gdata
src = ${buildout:directory}/src/progect
exclude = tests
zip-packages = True
use_setuptools_pkg_resources = True
# We have a patch overriding imports to enable buildout and eggs
#patch = ${buildout:directory}/google_appserver.patch
[progectconfig]
recipe = collective.recipe.template
input = ${buildout:directory}/templates/app.yaml.in
output = ${progect:src}/app.yaml
[progectsettings]
recipe = collective.recipe.template
input = ${buildout:directory}/templates/settings.py.in
output = ${progect:src}/settings.py
[nosetests]
recipe = zc.recipe.egg
eggs =
NoseGAE
WebTest
progect
nose
extra-paths =
${buildout:directory}/etc
${buildout:directory}/parts/google_appengine
${buildout:directory}/parts/google_appengine/lib/antlr3
${buildout:directory}/parts/google_appengine/lib/django_1_3
${buildout:directory}/parts/google_appengine/lib/fancy_urllib
${buildout:directory}/parts/google_appengine/lib/ipaddr
${buildout:directory}/parts/google_appengine/lib/webob_1_1_1
${buildout:directory}/parts/google_appengine/lib/webapp2/
${buildout:directory}/parts/google_appengine/lib/yaml/lib
${buildout:directory}/parts/google_appengine/lib/simplejson
${buildout:directory}/parts/google_appengine/lib/graphy
interpreter = python
[noseconfig]
recipe = collective.recipe.template
input = ${buildout:directory}/templates/setup.cfg.in
output = ${buildout:directory}/setup.cfg
[zipsymlink]
recipe = svetlyak40wt.recipe.symlinks
path = ${progect:src}
files = ${progect:app-directory}/packages.zip
[versions]
Django = 1.3
gdata = 2.0.16
lxml = 2.3
PIL = 1.1.7
PyCrypto = 2.3
setuptools = 0.6c11
webapp2 = 2.3
WebOb = 1.1.1
WTForms = 1.0.1
# Tools and dependencies
svetlyak40wt.recipe.symlinks = 0.2.1
An app.yaml template can look like
application: ${buildout:appspotname}
version: ${buildout:appspotversion}
runtime: python27
threadsafe: true
api_version: 1
libraries:
- name: PIL
version: "${versions:PIL}"
- name: pycrypto
version: "${versions:PyCrypto}"
- name: django
version: "${versions:Django}"
- name: lxml
version: "${versions:lxml}"
- name: setuptools
version: "${versions:setuptools}"
- name: webapp2
version: "${versions:webapp2}"
- name: webob
version: "${versions:WebOb}"
handlers:
- url: /.*
script:hello_world.app
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.application
login: admin
builtins:
- deferred: on
Nose tests config template, running tests against src directory (as opposed to the main alternative parts/progect):
[nosetests]
verbosity=1
detailed-errors=1
with-gae=1
gae-application=${progect:src}
gae-lib-root=${buildout:directory}/parts/google_appengine
where=${progect:src}
When I want to set this up, I go to the buildout root directory and type
/path/to/appropriate/python bootstrap.py --distribute
bin/buildout -c buildout.cfg
and then I can run bin/nosetests
or bin/dev_appserver parts/progect
Upvotes: 2
Reputation: 7158
webapp2 is not included in the sdk, you need to either install the package to your python environment or include it in the buildout if you are using a sandbox or virtualenv within the buildout.
Upvotes: 0