我尝试了这个http://jazstudios.blogspot.com/2010/07/installing-mysql-python-mysqldb-in.html提示在virtualenv(名为 dogme )中安装mysql-python(mysqldb)。 (这篇文章指出了两件重要的事情:
export ARCHFLAGS="-arch x86_64"
echo "mysql_config = /opt/local/bin/mysql_config5" >> ./dogme/build/MySQL-python/site.cfg
帮助编译mysqldb)
但是,当我运行python,导入MySQLdb时,我得到了这个:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.virtualenvs/dogme/lib/python2.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so
Expected in: flat namespace
in /home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so
任何人都明白什么是错的?
答案 0 :(得分:2)
我有类似的问题,看看我的追溯:
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
Referenced from: /Library/Python/2.6/site-packages/_mysql.so
Reason: image not found
我所做的是将这些变量放在我的.bash_profile
:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH"
当我使用Apache运行Python CGI应用程序时,我使用SetEnv指令设置了相同的变量:
<Directory "/path/to/app">
SetEnv DYLD_LIBRARY_PATH /usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
...
</Directory>
现在一切正常。