【问题标题】:ImportError: No module named SQLAlchemy. GAE and webapp2ImportError:没有名为 SQLAlchemy 的模块。 GAE 和 webapp2
【发布时间】:2014-06-21 14:44:30
【问题描述】:

我正在尝试在谷歌应用引擎上使用 SQLAlchemy 和 webapp2。我正在 eclipse 中开发,eclipse 将 from sqlalchemy import create_engine 识别为有效导入。但是,当我运行 GAE 项目并访问 localhost:8080 时,我收到以下错误:

Traceback (most recent call last):

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle

handler = _config_handle.add_wsgi_middleware(self._LoadHandler())

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py",     line 298, in _LoadHandler

handler, path, err = LoadObject(self._handler)

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject

obj = __import__(path[0])

File "C:\Users\Matthew\Development\Python\repos\trainingdb\app_engine_workspace\TrainingEngineProject\main.py", line 2, in <module>

import handlers

File "C:\Users\Matthew\Development\Python\repos\trainingdb\app_engine_workspace\TrainingEngineProject\handlers.py", line 2, in <module>

from sqlalchemy import create_engine

ImportError: No module named sqlalchemy

INFO     2014-06-21 10:30:05,214 module.py:639] default: "GET / HTTP/1.1" 500 -

这是我的项目文件:

app.yaml

application: tdg-manager
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /static
  static_dir: static
- url: /
  script: main.app

libraries:
- name: webapp2
  version: latest

ma​​in.py

import webapp2
import handlers

routes = [
    (r'/', handlers.MainHandler),
]
app = webapp2.WSGIApplication(routes=routes,
                              debug=True)

handlers.py

import webapp2
from sqlalchemy import create_engine

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write("Hello world")

总的来说,我对 GAE 和 Web 开发还比较陌生,所以我可能遗漏了一些明显的东西。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: python google-app-engine sqlalchemy importerror webapp2


    【解决方案1】:

    在您的本地计算机上安装了 sqlalchemy。在 appengine 上,您没有它,这就是您的导入失败的原因。

    【讨论】:

    • 是的,但是如何在 appengine 上安装它?
    • 只需将它的安装复制到与您的 app.yaml 相同的目录中,然后导入即可。
    • 他/她已经表示他/她在本地机器上遇到了问题。
    猜你喜欢
    • 2012-05-21
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 2014-03-14
    相关资源
    最近更新 更多