金字塔框架:Apache + mod_wsgi - MySQLdb导入错误

时间:2012-07-30 20:41:51

标签: python apache mod-wsgi pyramid

这是我的第一个金字塔应用程序,我已经尝试了我能找到的解决方案,但没有一个适合我。我一直收到内部服务器错误,错误日志显示:

Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]     import MySQLdb as mysql
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]   File "build/bdist.macosx-10.7-            intel/egg/MySQLdb/__init__.py", line 19, in <module>
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]   File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]   File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1] ImportError: dlopen(/Users/anupamtulsyan/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]   Referenced from: /Users/anupamtulsyan/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
[Tue Jul 31 02:02:23 2012] [error] [client 127.0.0.1]   Reason: image not found
[Tue Jul 31 02:02:24 2012] [error] [client 127.0.0.1] File does not exist: /opt/local/apache2/htdocs/favicon.ico

我的mysql和python都是64位安装。文件'libmysqlclient.18.dylib'存在于/ usr / local / mysql / lib中。 我可以使用以下方法在为应用程序提供服务时导入MySQLdb: ../bin/pserver development.ini 但是当运行mod_wsgi时,上述错误不断出现。请有人帮忙!我从那以后就被困在这两天了。

1 个答案:

答案 0 :(得分:2)

看起来libmysqlclient.18.dylib不在Apache的路径上。所以你可能需要在/usr/sbin/envvars中设置它:

DYLD_LIBRARY_PATH="/usr/lib:/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

取决于你的mysql lib的位置,然后重新启动apache。

我认为你也可以在构建MySQLdb之前设置DYLD_RUN_PATH,它将在_mysql.so中使用该路径 - 无需设置DYLD_LIBRARY_PATH