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,就沒有錯誤了