我正在尝试在 Google App 引擎中使用 CherryPY 框架运行 Web 应用程序。我无法在本地开发服务器中运行基本的 helloworld 代码(来自下载的 SDK)
我收到ImportError:没有名为cherrypy的模块
。虽然我安装了
cherrypy 使用 pip install ,相同的代码可以使用
python hello.py
(删除 google 导入)
这是我的hello.py
import random
import string
import cherrypy
from google.appengine.ext.webapp.util import run_wsgi_app
class StringGenerator(object):
@cherrypy.expose
def index(self):
return "Hello world!"
@cherrypy.expose
def generate(self):
return ''.join(random.sample(string.hexdigits, 8))
if __name__ == '__main__':
cherrypy.quickstart(StringGenerator(), '/')
和我的app.yaml文件
version: 1
runtime: python27
api_version: 1
threadsafe: true
# [START handlers]
handlers:
- url: /.*
script: hello.app
# [END handlers]
# [START libraries]
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
# [END libraries]
最佳答案
Cherrypy 并未捆绑为 App Engine 的一部分,但由于它是一个纯 Python 框架,因此您可以通过供应商将其添加到您的项目中,以便开发服务器可以选择它:
$ mkdir lib
$ pip install -t lib cherrypy
在应用程序的根目录中创建一个新的 appengine_config.py
文件,其位置与 app.yaml
等相同......包含以下内容:
from google.appengine.ext import vendor
vendor.add('lib')
关于python - 在 Google App 引擎中运行 Cherrypy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31360267/