日期:2014-05-16  浏览次数:20454 次

linux python2.7 mysqldb 安装
异常  Google之说是centos下安装了MySQL-python之后还得安装python-devel 和 mysql-devel:yum install python-devel mysql-devel,但是重启mysqld 之后仍然出错。

使用easy_install-2.7 MySQL-python 出现错误:
_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:
_mysql.c:2444: 错误:‘_mysql_ConnectionObject’ 没有名为 ‘open’ 的成员
error: Setup script exited with error: command ‘gcc’ failed with exit status 1

再使用Distutils安装:
下载mysql-python:http://sourceforge.net/projects/mysql-python/
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
tar zxvf MySQL-python-1.2.3.tar.gz -C /opt
cd /opt/MySQL-python-1.2.3
python2.7 setup.py install
出现同样错误:
_mysql.c:36:23: 错误:my_config.h:没有那个文件或目录
_mysql.c:38:19: 错误:mysql.h:没有那个文件或目录
_mysql.c:39:26: 错误:mysqld_error.h:没有那个文件或目录
_mysql.c:40:20: 错误:errmsg.h:没有那个文件或目录
_mysql.c:76: 错误:expected specifier-qualifier-list before ‘MYSQL’
_mysql.c:90: 错误:expected specifier-qualifier-list before ‘MYSQL_RES’
_mysql.c: In function ‘_mysql_Exception’:
_mysql.c:120: 警告:隐式声明函数 ‘mysql_errno’
….
_mysql.c:2422: 错误:初始值设定元素不是常量
_mysql.c:2422: 错误:(在 ‘_mysql_ResultObject_memberlist[0].offset’ 的初始化附近)
_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:
_mysql.c:2444: 错误:‘_mysql_ConnectionObject’ 没有名为 ‘open’ 的成员
error: command ‘gcc’ failed with exit status 1
Linux Python如何安装Mysqldb模块这篇文章介绍解决办法为:
vi site.cfg 将 #mysql_config = /usr/local/bin/mysql_config 注释去掉并改成本地的正确位置:
mysql_config = /usr/bin/mysql_config。但仍然出现同样错误。查看提示 vi README,需要mysql-devel:
* Red Hat Linux packages:
- mysql-devel to compile
- mysql and/or mysql-devel to run
安装 yum install mysql-devel,再执行:python2.7 setup.py install,编译安装Mysqldb模块成功: