mod_wsgi无法加载mysql

时间:2011-03-13 21:00:49

标签: python mysql apache mod-wsgi trac

首先,我将列出我的环境和状态:

环境:

  • 系统:Mac OS 10.6
  • Python:2.6
  • Apache:2.2
  • mod_wsgi:3.3
  • mysql:5.x
  • php:3.5
  • TRAC:0.12

状态: 我可以毫无问题地将trac作为独立服务器运行。 现在我将trac集成到apache,问题就出来了。 mod_wsgi可以正常运行正常的wsgi页面,但无法加载mysql连接。我在一段代码中测试它,在wsgi页面中输入“ import MySQLdb ”,它仍然不能。我也可以通过apache访问trac,但它显示我无法加载MySQL的Python绑定

我指的是apache日志:

[Sun Mar 13 13:36:44 2011] [error] [client ::1] mod_wsgi (pid=37060): Target WSGI script /Users/alex/Library/apache2/htdocs/sql.wsgi' cannot be loaded as Python module.

[Sun Mar 13 13:36:44 2011] [error] [client ::1] mod_wsgi (pid=37060): Exception occurred processing WSGI script '/Users/alex/Library/apache2/htdocs/sql.wsgi'.

[Sun Mar 13 13:36:44 2011] [error] [client ::1] Traceback (most recent call last):

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "/Users/alex/Library/apache2/htdocs/sql.wsgi", line 2, in <module>

[Sun Mar 13 13:36:44 2011] [error] [client ::1]     import MySQLdb

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__

[Sun Mar 13 13:36:44 2011] [error] [client ::1] ImportError: dlopen(/Users/alex/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   Referenced from: /Users/alex/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so

[Sun Mar 13 13:36:44 2011] [error] [client ::1]   Reason: image not found

[Sun Mar 13 13:36:57 2011] [error] [client ::1] mod_wsgi (pid=37061): Target WSGI script

这看起来像mod_wsgi找不到libmysqlclient.16.dylib。我为python安装mysqldb时会遇到类似的问题,所以我添加了导出

DYLD_LIBRARY_PATH=/Users/alex/Library/mysql-5.x/lib

SO python -c“import MySQLdb”可以工作,但是mod_wsgi无法正常工作。 所以我把

os.environ['DYLD_LIBRARY_PATH'] = '/Users/alex/Library/mysql-5.x/lib'

进入trac.ini。 它仍然适用于apache中的trac。

所以之前有人有这个问题吗? 感谢

2 个答案:

答案 0 :(得分:0)

尝试 LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql:$LD_LIBRARY_PATH

答案 1 :(得分:0)

问题是你的Apache运行为64位,而你使用的是32位版本的MySQL,或者Apache运行的是32位,你使用的是64位版本的MySQL。

在'libmysqlclient.16.dylib'上运行'file'命令,它会告诉你它是为它构建的架构。在以下位置查看实际Python扩展的类似问题:

http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX#Missing_Code_For_Architecture

您需要获取远程MySQL库二进制文件或强制Apache以相同的体系结构运行。链接的文档有一些可以做的准则。