mac下安装mysql-python,下载源码在: http://sourceforge.net/projects/mysql-python/files/?source=navbar
解压后执行 python setup.py build
报出错误为:
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 18, in <module>
metadata, options = get_config()
File "/Users/dongquan/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/Users/dongquan/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
解决的办法是,修改 安装目录下,site.cfg,
约12行附近,增加 mysql_config = /usr/local/mysql/bin/mysql_config
用来指定mysql的安装位置
继续执行 python setup.py build,
然后安装,执行sudo python setup.py install,安装完毕
在命令行中测试import MySQLdb,会曝出错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "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): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
Reason: image not found
解决方法: 创建libmysqlclient.18.dylib的“快捷方式”
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/
再次执行import MySQLdb,就没有错误了