公司测试机环境不知道给我卸了什么包,导致yum运行报错状况:
系统版本:CentOS release 6.7 (Final)
报错情况:
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named sqlite
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:
一、升级或卸载Python导致:
1、查看已安装python的版本,可能是当前系统存在多个python导致
[root@test ~]# whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.6-config /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
[root@test ~]# vi /usr/bin/yum
将 #!/usr/bin/python 修改为 #!/usr/bin/python2.6
如果是源代码安装的,默认路径是/usr/local/bin/python2.6,做个软链接即可
rm -rf /usr/bin/python
ln -s /usr/local/bin/python2.6 /usr/bin/python
二、完全重装python和yum
1、删除现有Python
[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test ~]# whereis python ##验证删除,返回无结果
2、删除现有的yum
[root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test ~]# whereis yum |xargs rm -frv
3、从http://mirrors.163.com/centos/6/os/x86_64/Packages/下载相应的包
python-2.6.6-66.el6_8.x86_64.rpm
python-devel-2.6.6-66.el6_8.x86_64.rpm
python-iniparse-0.3.1-2.1.el6.noarch.rpm
python-libs-2.6.6-66.el6_8.x86_64.rpm
python-pycurl-7.19.0-9.el6.x86_64.rpm
python-setuptools-0.6.10-3.el6.noarch.rpm
python-urlgrabber-3.9.1-11.el6.noarch.rpm
rpm-python-4.8.0-55.el6.x86_64.rpm
yum-3.2.29-81.el6.centos.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
yum-plugin-aliases-1.1.30-40.el6.noarch.rpm
yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
yum-plugin-protectbase-1.1.30-40.el6.noarch.rpm
yum-utils-1.1.30-40.el6.noarch.rpm
由于源中版本会更新,具体请查看URL中的版本再下载下来!
[root@test ~]# rpm -Uvh --replacepkgs python*.rpm
[root@test ~]# rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm
**如果运行时报:
error: Failed dependencies:
libxml2 = 2.7.6-21.el6_8.1 is needed by libxml2-python-2.7.6-21.el6_8.1.x86_64
则需要下载
libxml2-2.7.6-21.el6_8.1.x86_64.rpm
libxml2-devel-2.7.6-21.el6_8.1.x86_64.rpm
libxml2-python-2.7.6-21.el6_8.1.x86_64.rpm
三个包
rpm -Uvh --replacepkgs libxml2*.rpm
***如果运行时报:
error: Failed dependencies:
rpm = 4.8.0-55.el6 is needed by rpm-python-4.8.0-55.el6.x86_64
或者报
error: Failed dependencies:
rpm = 4.8.0-47.el6 is needed by (installed) rpm-libs-4.8.0-47.el6.x86_64
rpm = 4.8.0-47.el6 is needed by (installed) rpm-devel-4.8.0-47.el6.x86_64
rpm = 4.8.0-47.el6 is needed by (installed) rpm-build-4.8.0-47.el6.x86_64
则需要下载
rpm-4.8.0-55.el6.x86_64.rpm
rpm-build-4.8.0-55.el6.x86_64.rpm
rpm-devel-4.8.0-55.el6.x86_64.rpm
rpm-libs-4.8.0-55.el6.x86_64.rpm
四个包
rpm -Uvh --replacepkgs rpm-*.rpm
可能之间还需要zlib和zlib-devel包,根据情况下载并安装!直到
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm
后显示
Preparing... ########################################### [100%]
1:yum-metadata-parser ########################################### [ 14%]
2:rpm-python ########################################### [ 29%]
3:yum-plugin-fastestmirro########################################### [ 43%]
4:yum ########################################### [ 57%]
5:yum-utils ########################################### [ 71%]
6:yum-plugin-aliases ########################################### [ 86%]
7:yum-plugin-protectbase ########################################### [100%]
三、运行python进行测试
[root@test ~]# python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
>>>
如上,要是什么都没报,则说明OK啦~