Python AppEngine'导入MySQLdb'无效,OS X 10.9.2,python 2.7

时间:2014-05-15 20:28:16

标签: python mysql google-app-engine python-2.7 mysql-python

我已成功为我的系统python安装了MySQLdb - 我也已将该库添加到app.yaml,但dev-appserver无法识别它。我已按照此处的教程进行操作:https://developers.google.com/appengine/docs/python/cloud-sql/

我从这里下载并安装了最新的Python mysql: http://sourceforge.net/projects/mysql-python/

sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments python setup.py build
sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments python setup.py install

如果我从命令行运行python,我可以愉快地导入MySQLdb

这是我在app.yaml中的内容:

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: "2.6"
- name: MySQLdb
  version: "1.2.4b4"

这是我尝试打开由appengine dev服务器托管的页面时遇到的异常。

ERROR    2014-05-15 20:23:19,480 wsgi.py:262] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "xxxx/main.py", line 10, in <module>
    import MySQLdb
ImportError: No module named MySQLdb

任何帮助都将深表感谢 - 教程不起作用。谢谢你的慷慨和善意!

-s

2 个答案:

答案 0 :(得分:3)

以下对我有用。我从App Engine得到了同样的错误,但事实证明问题是模块_mysql未正确配置。

将此添加到~/.bash_profile

export PATH=$PATH:/usr/local/mysql/bin

创建MySQL lib的符号链接:

ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

答案 1 :(得分:1)

我在本地开发方面遇到了同样的问题,并且在一段时间内遇到了困难。最后,我编写了所有查询的命令行版本,测试了它们,然后完全部署了应用程序。它从那里起作用。

如果您找到允许本地开发的解决方案,请在此处发布。