我需要做buildout谷歌应用引擎。我写了配置文件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
运行命令python<(curl http://python-distribute.org/bootstrap.py)--distribute和./bin/buildout GAE不想工作。服务器正在运行,但GAE站点中最简单的Hello世界显示错误importError:没有名为webapp2的模块。首先,我需要在我的脚本之后运行Hello world。文件和文件夹结构是: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.
答案 0 :(得分:2)
webapp2包含在最近的SDK中(google_appengine / lib / webapp2)。如果您使用较新的SDK或不导入webapp2,它应该适合您。
如果您对稍微不同的构建设置感兴趣,我已经包含了一个。
我一直在使用rod.recipe.appengine进行扩建,并对它非常满意。如果您需要修复PyCrypto imports等,它甚至允许您修补应用引擎SDK。
我根据bobo example和其他一些来源制作了我的配置。下面的示例允许您从dist.plone.org获取PIL之类的依赖关系,它为表单处理提取wtforms,为加密方便提取gdata,并将它们放在packages.zip中,可以在导入之前添加到sys.path,例如{ {1}} zippedpackages.py看起来像
import zippedpackages
另请注意,settings.py和app.yaml是通过模板生成的,并且插入了import sys
if 'packages.zip' not in sys.path:
sys.path.insert(0, 'packages.zip')
和appspotname
等变量。
buildout基于正在运行的buildout,但是这个确切的示例尚未经过测试,并且还缺少一些模板。如果你在pypi上查找不同的食谱,你可以阅读选项和语法。
如果使用模板,则可能必须运行buildout两次才能首先从模板生成文件(在我的设置中的src目录中),然后创建符号链接到parts目录(SDK运行的位置)。如果您不想要模板,请从buildout中删除并像平常一样进行设置。使用egg而不是virtualenv使您可以将库切换为配置而不是具有不同的virtualenv。但不是一个大问题,因为库版本很少改变。如果你遇到鸡蛋的问题,还值得注意的是SDK导入魔法知道站点包,在某种程度上知道virtualenvs,但不是蛋,所以有些库可能必须安装在virtualenv中。
appspotversion
app.yaml模板看起来像
[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
Nose测试配置模板,针对src目录运行测试(而不是主要的替代部件/ progect):
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
当我想设置它时,我转到buildout根目录并输入
[nosetests]
verbosity=1
detailed-errors=1
with-gae=1
gae-application=${progect:src}
gae-lib-root=${buildout:directory}/parts/google_appengine
where=${progect:src}
然后我可以投放/path/to/appropriate/python bootstrap.py --distribute
bin/buildout -c buildout.cfg
或bin/nosetests
答案 1 :(得分:0)
webapp2未包含在sdk中,如果您在buildout中使用沙箱或virtualenv,则需要将软件包安装到python环境中或将其包含在buildout中。