首页 > Linux > linux下yum出错的2种情况:There was a problem importing one of the Python modules

linux下yum出错的2种情况:There was a problem importing one of the Python modules

有一天突然发现centos的yum无法使用了,只遇到以下错误信息:

There was a problem importing one of the Python modules

required to run yum. The error leading to this problem was:


   pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)


Please install a package which provides this module, or

verify that the module is installed correctly.


It's possible that the above module doesn't match the

current version of Python, which is:

2.7.5 (default, Jun 17 2014, 18:11:42) 

[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]


If you cannot solve this problem yourself, please go to 

the yum faq at:

http://yum.baseurl.org/wiki/Faq



于是查了一下资料,都说是python的版本不对,因为目前的yum只支持python2.4及以下版本,然后我查了一下本机的python版本:

[root@localhost bin]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7 /usr/local/python2.4 /usr/local/python2.6 /usr/share/man/man1/python.1.gz

咋一看挺多了,然后进度到/usr/bin目录查看详情:

[root@localhost bin]# ll|grep python
-rwxr-xr-x.   1 root root      11216 Jun 19  2014 abrt-action-analyze-python
lrwxrwxrwx.   1 root root          7 Nov 21  2014 python -> python2
lrwxrwxrwx.   1 root root          9 Nov 21  2014 python2 -> python2.7
-rwxr-xr-x.   1 root root       7136 Jun 18  2014 python2.7
-rwxr-xr-x    1 root root       1835 Jun 18  2014 python2.7-config.bak
lrwxrwxrwx    1 root root         16 Aug 17 15:49 python2-config -> python2.7-config
lrwxrwxrwx    1 root root         14 Aug 17 15:49 python-config -> python2-config

细看之后才发现我只有一个python2.7的版本,我保证从未升级过python的版本,可是为何以前能用yum而现在用不了?网上都说python版本过高引起的,于是我怀着试一试的态度下载Python-2.4.tar.bz2编译安装,然后修改yum:

[root@localhost bin]# vi /usr/bin/yum
#!/usr/local/python2.4/bin/python

原理很简单,使用2.4版本的python,接着运行yum安装又报错了:

It's possible that the above module doesn't match the
current version of Python, which is:
2.4 (#1, Dec  5 2015, 19:39:42) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]

瞬间觉得被坑了,后来仔细对比了我遇到的错误和别人遇到的错误,才发现不同之处:

[root@develop bin]# yum  

[root@develop local]# yum -y install prce  

There was a problem importing one of the Python modules  

required to run yum. The error leading to this problem was:  

  

  

   No module named yum  

  

  

Please install a package which provides this module, or  

verify that the module is installed correctly.  

  

  

It's possible that the above module doesn't match the  

current version of Python, which is:  

2.6.1 (r261:67515, Aug 7 2010, 11:36:17)  

[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)]  

  

  

If you cannot solve this problem yourself, please go to  

the yum faq at:  


http://wiki.linux.duke.edu/YumFaq

这才发现红色区域部分的不同之处,倒腾了这么久,原来我被自己坑了,这才硬着头皮使用pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)进行搜索,原来是pycurl出错需要重装:

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
pip install pycurl

重装之后,yum果然恢复使用。以后遇到问题不要着急,根据报错信息搜索资料,虽然网上各位都有自己的解决办法,但是你也需要一双火眼来分辨遇到的问题是不是同一个!

总结一下,这次yum出错是pycurl出错导致的,与python版本无关,可能是我的操作系统比较新(Centos7.0)的yum是支持python2.7.5的。

如果遇到的问题是No module named yum”这时再考虑低版本的python。

教程地址:http://blog.zhengshuiguang.com/linux/yum-python.html

欢迎转载!但请带上文章地址^^

标签:python yum出错 重装pycurl

评论已关闭