mac下解决python访问mysql的组件mysql-python异常的bug
问题:
mac系统为10.9,安装mysql server,python为2.7,在访问mysql时,报:Traceback (most recent call last):
File "tests/test_MySQLdb_capabilities.py", line 4, in <module>
import MySQLdb
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/MySQLdb/init.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so: mach-o, but wrong architecture
过程:file`whichpython`
$ file `which mysql` # or mysql_config $ file /Library/Python/2.7/site-packages/_mysql.so
解决办法:
1. uninstall MySQL and mysql-python
2. reinstall MySQL 64-bit
3. reinstall mysql-python
(at this point, the django syncdb command was failing due to a missing library, libmysqlclient.18.dylib)
4. added environment variable DYLD_LIBRARY_PATH=/usr/local/mysql...../lib, to point to the directory containing the missing dylib