无法在 virtualenv 中安装 mySQL-python

Posted

技术标签:

【中文标题】无法在 virtualenv 中安装 mySQL-python【英文标题】:cannot install mySQL-python in virtualenv 【发布时间】:2015-01-13 06:52:15 【问题描述】:

当我尝试在 virtualenv (pip install mysql-python) 中安装 MySQL-python 时,我收到以下错误(截断到最后几行)

_mysql.c: At top level:
_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

谷歌搜索告诉我我需要安装 python-devel,虽然当我运行 yum install python-devel 时我得到了

Package python-devel-2.6.6-52.el6.x86_64 already installed and latest version
Nothing to do

我在安装了 python 2.6 和 2.7 的 CentOS 6.5 机器上。我在我的 virtualenvs 中使用 python 2.7。我在运行pip install mySQL-python 时激活了 virtualenv。

我尝试在激活和停用 virtualenv 的情况下运行 yum install python-devel,两次都显示“已安装”消息。

这是否意味着 python 27 安装没有得到python-devel 安装?

另一个线程建议尝试yum install mysql-devel.x86_64,尽管这给出了

Resolving Dependencies
--> Running transaction check
---> Package mysql-devel.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Dependency: mysql = 5.1.73-3.el6_5 for package: mysql-devel-5.1.73-3.el6_5.x86_64
--> Finished Dependency Resolution
Error: Package: mysql-devel-5.1.73-3.el6_5.x86_64 (base)
           Requires: mysql = 5.1.73-3.el6_5
           Installed: mysql-5.5.40-1.el6.remi.x86_64 (@remi)
               mysql = 5.5.40-1.el6.remi
           Available: mysql-5.1.73-3.el6_5.x86_64 (base)
               mysql = 5.1.73-3.el6_5
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

(使用--skip-broken 不起作用,它只是跳过它)

【问题讨论】:

【参考方案1】:

已解决:我需要运行 sudo yum --enablerepo=remi install mysql-devel

然后,运行 pip install MySQL-python 工作(激活了我的 virtualenv)

看到这个答案https://serverfault.com/questions/601162/cant-install-mysql-devel-on-centos-6-5

(我发誓我在发帖前搜索了大约 1.5 小时)

【讨论】:

以上是关于无法在 virtualenv 中安装 mySQL-python的主要内容,如果未能解决你的问题,请参考以下文章

在 virtualenv 中安装 Django:MySQL-python 错误

在 Windows 7 上的 virtualenv 中安装 MySQL-python

如何在python2.7中安装MySQLdb 在virtualenv中安装

无法在 virtualenv 中安装 psycopg2 “错误:stdarg.h:没有这样的文件或目录”

在virtualenv中安装mysqlclient时出错

无法让这些配合:mysql-python + virtualenv + percona + centos6