1.下載源碼包水醋,解壓安裝
python setup.py install
報錯:
[root@oss-cdn-monitor-bjb-001 MySQL-python-1.2.4]# python setup.py install
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Extracting in /tmp/tmp4CbWr7
Now working in /tmp/tmp4CbWr7/distribute-0.6.28
Building a Distribute egg in /home/MySQL-python-1.2.4
/home/MySQL-python-1.2.4/distribute-0.6.28-py2.6.egg
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 18, in <module>
metadata, options = get_config()
File "/home/MySQL-python-1.2.4/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/home/MySQL-python-1.2.4/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
原因是未安裝mysql客戶端旗笔,或者是源碼安裝的mysql,找不到路徑拄踪。如果是未安裝蝇恶,yum -y install mysql安裝即可。如果是源碼安裝惶桐,需要如下步驟
找到mysql_config文件路徑撮弧,執(zhí)行如下命令
find / -name mysql_config ,比如在/usr/local/mysql/bin/mysql_config
修改setup_posix.py文件姚糊,在26行:mysql_config.path = “mysql_config” 修改為:
mysql_config.path = “/usr/local/mysql/bin/mysql_config”
保存后贿衍,然后再次執(zhí)行:
python setup.py build
python setup.py install
2.再次執(zhí)行python setup.py install,又有新報錯
_mysql.c:2982: error: expected ‘=’, ‘,’, ‘;’, ‘a(chǎn)sm’ or ‘__attribute__’ before ‘*’ token
_mysql.c:3030: warning: return type defaults to ‘int’
_mysql.c: In function ‘DL_EXPORT’:
_mysql.c:3030: error: expected declaration specifiers before ‘init_mysql’
_mysql.c:3138: error: expected ‘{’ at end of input
error: command 'gcc' failed with exit status 1
原以為是未安裝gcc救恨,結(jié)果不是贸辈,原因是未安裝python-devel,mysql-devel
yum -y install python-devel