2012-05-25 110 views
0

我需要建立谷歌应用程序引擎。我写的配置文件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 <(卷曲http://python-distribute.org/bootstrap.py)-distribute和./bin/buildout GAE不`吨想要的工作。服务器正在运行,但来自GAE站点的最简单的Hello World显示错误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. 

回答

2

webapp2包含在最近的SDK中(google_appengine/lib/webapp2)。如果您使用较新的SDK或不导入webapp2,它应该适合您。

如果您对稍微不同的buildout设置感兴趣,我已经包含了一个。

我一直在使用rod.recipe.appengine进行构建,并且一直很满意它。它甚至可以让你,如果你需要修复PyCrypto imports修补应用程序引擎SDK等

我做基础上,BOBO example和一些其他来源我的配置。下面的示例允许您从dist.plone.org获得PIL等依赖项,它为表单处理提供wtforms,为crypto提供便利的gdata,并将它们放入packages.zip中,这些packages.zip可以在导入之前添加到sys.path中,例如import zippedpackages其中zippedpackages.py看起来像

import sys 
if 'packages.zip' not in sys.path: 
    sys.path.insert(0, 'packages.zip') 

还要注意的是settings.py和app.yaml中是通过模板和变量产生像appspotnameappspotversion插入。

构建基于正在运行的构建,但该确切示例尚未经过测试,并且也缺少一些模板。如果你在pypi上查看不同的食谱,你可以阅读选项和语法。

如果您使用模板,您可能需要两次运行构建以便首先从模板生成文件(位于我的设置中的src目录中),然后创建部件目录(SDK运行所在的部分)的符号链接。如果您不需要模板,请从buildout中删除并按照正常方式进行设置。使用鸡蛋而不是virtualenv,可以将库切换为配置,而不是具有不同的virtualenvs。虽然不是一个大问题,因为图书馆版本很少改变。如果遇到与鸡蛋有关的问题,还值得注意的是,SDK导入魔术知道网站包和某种程度上的virtualenvs,但不是蛋,所以有些库可能必须安装在virtualenv中。

[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 

一个应用程序。YAML模板可以像

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 

鼻测试配置模板,运行针对src目录测试(相对于主要的替代部件/ 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} 

当我想设置此,我转到扩建根目录,然后键入

/path/to/appropriate/python bootstrap.py --distribute 
bin/buildout -c buildout.cfg 

,然后我可以运行bin/nosetestsbin/dev_appserver parts/progect

+0

谢谢,问题完成了 – voha

0

webapp2的不包括在SDK中,您需要将包或者安装到您的Python环境或包括如果你在构建中使用沙盒或virtualenv,那么它在构建中。

+0

我正在使用virtualenv。我如何将webapp2包含到我的构建中? – voha

+0

你是通过构建还是手动设置virtualenv? – aschmid00

+0

我手动创建virtualenv。你能写我示例buildout? – voha