安装mysql-python

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 
    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文件路径,执行如下命令
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”
保存后,然后再次执行:
python setup.py build
python setup.py install

2.再次执行python setup.py install,又有新报错

_mysql.c:2982: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ 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,结果不是,原因是未安装python-devel,mysql-devel
yum -y install python-devel

你可能感兴趣的:(安装mysql-python)