ImportError:没有名为SQLAlchemy的模块。GAE和webapp2

1 投票
1 回答
1125 浏览
提问于 2025-04-18 10:36

我正在尝试在谷歌应用引擎上使用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

main.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和网页开发还比较陌生,可能遗漏了一些明显的东西。任何帮助都将非常感激。谢谢!

1 个回答

0

在你的本地电脑上,你已经安装了sqlalchemy这个库。但在appengine上,你没有安装它,所以你的导入操作失败了。

撰写回答