Google app engine + python(django)部署错误:加载MySQLdb模块时出错

问题描述 投票:3回答:3

我正在Google App Engine上创建一个应用。 我正在使用Django 1.4和Python 2.7。 在localhost上一切正常。 但是在部署之后它没有运行,我继续在管理日志上得到这个:

    2012-12-15 15:02:41.870

    /base/python27_runtime/python27_lib/versions/1/lib/cacerts/urlfetch_cacerts.txt missing; without this urlfetch will not be able to validate SSL certificates.

    W 2012-12-15 15:02:41.870

    No ssl package found. urlfetch will not be able to validate SSL certificates.

    E 2012-12-15 15:02:46.086

    Traceback (most recent call last):
      File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 196, in Handle
        handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
      File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in _LoadHandler
        __import__(cumulative_path)
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/main/__init__.py", line 28, in <module>
        setup_env()
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/boot.py", line 82, in setup_env
        setup_logging()
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/boot.py", line 130, in setup_logging
        if not settings.DEBUG:
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/utils/functional.py", line 276, in __getattr__
        self._setup()
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/conf/__init__.py", line 42, in _setup
        self._wrapped = Settings(settings_module)
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/conf/__init__.py", line 87, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/utils/importlib.py", line 35, in import_module
        __import__(name)
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/settings.py", line 6, in <module>
        import django.db.backends.mysql.base
      File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/db/backends/mysql/base.py", line 14, in <module>
        raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
    ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

任何想法为什么会发生?

python django google-app-engine mysql-python
3个回答
7
投票

“Django支持”文档暗示了解决方案,但没有明确说明:

由于标准的django.db.backends.mysql后端在内部使用MySQLdb,app.yaml必须在库列表中引用MySQLdb。

将以下内容添加到app.yaml似乎修复了ImportError:

libraries:
- name: MySQLdb
  version: "latest"

请注意,MySQLdb当前未包含在可用的第三方库列表中。 我一时兴起尝试,似乎已经为我解决了问题,YMMV。 在此输入链接描述


2
投票

正如Cloud SQL文档明确指出的那样,您应该使用''google.appengine.ext.django.backends.rdbms'作为数据库引擎设置。


0
投票

如果在将以下内容添加到app.yaml后它无效:

libraries:
- name: MySQLdb
  version: "latest"

...然后采取以下步骤:

  1. 确保在Mac上pip install mysql-python MySQLdb pip install mysql-python
  2. 确保GAE devserver指向你的virtualenv / pip'd python 2.7安装与Mac / * nix的默认版本,因为pip可能没有安装它。 我解决了Can't find module: MySQLdb通过更新GAE devserver来使用: /usr/local/bin/python2.7例如在GAE devserver偏好中为Python Path

注意:可以通过应用程序菜单访问首选项:

  • 如果您使用的是Windows:请在“ File > Preferences...下查找File > Preferences...
  • 如果您使用的是Mac,请查看GoogleAppengineLauncher > Preferences...
© www.soinside.com 2019 - 2024. All rights reserved.