mod_wsgi无法加载mysql

0 投票
2 回答
1477 浏览
提问于 2025-04-16 13:37

首先,我来列一下我的环境和状态:

环境:

  • 系统: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连接。我在一段代码中测试,放了import MySQLdb在wsgi页面里,结果还是不行。我也可以通过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时遇到过类似的问题,所以我添加了export

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

这样python -c "import MySQLdb"可以正常工作,但mod_wsgi还是不行。 所以我把

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

放进了trac.ini文件里。 但在apache中trac还是不工作。

有没有人之前遇到过这个问题? 谢谢

2 个回答

0

问题在于,你的Apache服务器是64位的,而你使用的是32位版本的MySQL,或者相反,Apache是32位的,而MySQL是64位的。

你可以在'libmysqlclient.16.dylib'上运行'file'命令,这样可以查看它是为哪种架构构建的。有关实际Python扩展的类似问题,可以参考以下链接:

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

你需要找到一个合适的MySQL库的二进制文件,或者让Apache以相同的架构运行。链接中的文档提供了一些可以采取的指导。

0

试试用LD_LIBRARY_PATH

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

撰写回答