【问题标题】:buildout google app engine构建谷歌应用引擎
【发布时间】:2012-06-01 08:30:59
【问题描述】:

我需要构建谷歌应用引擎。我写了配置文件 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: No module named 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.

【问题讨论】:

    标签: google-app-engine


    【解决方案1】:

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

    如果您对稍微不同的构建设置感兴趣,我提供了一个。

    我一直在使用 rod.recipe.appengine 进行构建,并且对此非常满意。如果您需要修复 PyCrypto imports 等,它甚至允许您修补应用引擎 SDK。

    我根据 bobo example 和其他一些来源进行了配置。下面的示例允许您从 dist.plone.org 获取诸如 PIL 之类的依赖项,它提取 wtforms 用于表单处理和 gdata 以方便加密,并将它们放在可以在导入之前添加到 sys.path 的 packages.zip 中,例如使用 @ 987654323@ 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 运行的位置)的符号链接。如果您不想要模板,请从构建中删除并像往常一样进行设置。使用eggs 代替virtualenv 可以让您将库作为配置切换,而不是使用不同的virtualenv。不过问题不大,因为库版本很少改变。如果您遇到了 egg 问题,还值得注意的是 SDK 导入魔法可以识别站点包,并且在某种程度上知道 virtualenvs,但不知道 egg,因此无论如何可能必须在 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
    

    app.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 目录运行测试(与主要替代部分/项目相反):

    [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

    【讨论】:

      【解决方案2】:

      webapp2 不包含在 sdk 中,如果您在构建中使用沙箱或 virtualenv,则需要将包安装到您的 python 环境或将其包含在构建中。

      【讨论】:

      • 我正在使用 virtualenv。如何将 webapp2 包含到我的构建中?
      • 我手动创建 virtualenv。你能给我写个例子吗?
      • 将它安装到您的 virtualenv 中的最简单方法是从这里下载源代码 pypi.python.org/pypi/webapp2 并执行 path/to/virtualenv/python setup.py install。我认为您应该为示例构建提出一个新问题,它不适合这里。
      • 没有。我有虚拟环境。我想用 webapp 创建构建。所以这个webapp不需要单独安装
      猜你喜欢
      • 2015-01-31
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 2012-06-19
      相关资源
      最近更新 更多