Python访问MySQL的模块,以前叫MySQLdb,后来更名为mysql-python,安装似乎也有变化。
有时会遇到这样的问题:
$ sudo python setup.py
installsh: line 1: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 16, in ?
metadata, options = get_config()
File "/Users/farocco/MySQL-python-1.2.2/setup_posix.py", line 43, in
get_config
libs = mysql_config("libs_r")
File "/Users/farocco/MySQL-python-1.2.2/setup_posix.py", line 24, in
mysql_config
raise EnvironmentError, "%s not found" % mysql_config.path
EnvironmentError: mysql_config not found
按照mysql-python的文档一步步来做,仍然会遇到这种问题,其实原因出在mysql_config上。
首先需要定位到本机的mysql_config,此文件处在mysql安装位置的bin目录下(假设Mysql安装在/data/mysql下,则路径为/data/mysql/bin/mysql_config)
修改setup_posix.py文件,在26行显示地设定mysql_config:
mysql_config.path = "/data/mysql/bin/mysql_config"
再次运行
python setup.py build
python setup.py install
安装完成