0

2747

No module named yum解决

netxfly   发表于   2015 年 06 月 19 日

在机器中分别装了2个比系统默认版本高的python后,再次使用yum的时候发现报错了,如下: ```shell [root@localhost ~]# yum 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.8 (unknown, Jun 18 2015, 16:07:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq ``` yum是用python实现的,应该是默认执行时用了不匹配的版本,将yum中的python版本改到能import yum模块的即可。 - 查看系统中有哪些python ``` [root@localhost ~]# whereis python python: /usr/bin/python2.6-config /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.6-config /usr/local/bin/python /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/bin/python2.6 /usr/local/lib/python2.7 /usr/local/lib/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz ``` - 先测试2.6的 ``` [root@localhost ~]# /usr/bin/python2.6 Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import yum >>> exit() ``` 再测试默认2.7.10的 ``` [root@localhost ~]# python Python 2.7.10 (default, Jun 18 2015, 15:51:08) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import yum Traceback (most recent call last): File "", line 1, in ImportError: No module named yum >>> exit() ``` - 修改yum的默认python版本 ``` [root@localhost ~]# vim /usr/bin/yum #!/usr/bin/python2.6 ```

标签:linux 继续阅读