使用pip2.7安装MySQL-python时出错

4 投票
1 回答
1675 浏览
提问于 2025-04-18 04:13

我在centos6.4 64位系统上安装了Python2.7、virtualenv和pip2.7,因为系统默认的是Python2.6。

当我尝试用下面的命令安装mysqldb时,

pip2.7 install MySQL-python

出现了错误,而python-devel这个软件包已经安装好了。

_mysql.c:2551: error: '_mysql_ConnectionObject' has no member named 'open'

_mysql.c:2558: error: '_mysql_ConnectionObject' has no member named 'converter'

_mysql.c:2565: error: '_mysql_ConnectionObject' has no member named 'connection'

_mysql.c:2572: error: '_mysql_ConnectionObject' has no member named 'connection'

_mysql.c:2579: error: '_mysql_ConnectionObject' has no member named 'connection'

_mysql.c:2642: error: '_mysql_ResultObject' has no member named 'converter'

_mysql.c:2642: error: initializer element is not constant

_mysql.c:2642: error: (near initialization for '_mysql_ResultObject_memberlist[0].offset')

_mysql.c: In function '_mysql_ConnectionObject_getattr':

_mysql.c:2666: error: '_mysql_ConnectionObject' has no member named 'open'

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/MySQL-python/setup.py';exec(compile(getattr(tokenize,

'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-eNCiSQ-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/MySQL-python Storing debug log for failure in /root/.pip/pip.log

1 个回答

3

看起来你的系统没有安装mysql-devel这个软件包。这个软件包是必须的,因为它提供了MySQL-python包需要的源代码和头文件。

作为管理员,你可以运行

yum install mysql-devel

然后再试一次!

撰写回答