Python AppEngine 'import MySQLdb' 无法工作,OS X 10.9.2,python 2.7
我已经成功为我的系统Python安装了MySQLdb,并且也把这个库添加到了app.yaml文件里,但开发服务器却识别不了它。我按照这里的教程操作过: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开发服务器托管的页面时,出现了这个异常。
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 个回答
1
我之前在本地开发的时候也遇到过同样的问题,纠结了好一阵子。最后,我写了所有查询的命令行版本,测试了一下,然后才把应用程序完全部署上去。从那以后就没问题了。
如果你找到能让本地开发顺利进行的解决办法,请在这里分享一下。
3
下面的方法对我有效。我在使用App Engine时也遇到了同样的错误,但后来发现问题出在模块 _mysql
没有配置好。
你可以把以下内容添加到 ~/.bash_profile
文件中:
export PATH=$PATH:/usr/local/mysql/bin
接下来,创建一个指向MySQL库的符号链接:
ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib