无法在virtualenv中安装mySQL-python

时间:2014-11-16 06:13:05

标签: python python-2.7 pip virtualenv mysql-python

当我尝试在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 个答案:

答案 0 :(得分:6)

已解决:我需要运行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小时)