1. 程式人生 > >centos重新安裝,解除安裝python yum

centos重新安裝,解除安裝python yum

公司測試機環境不知道給我卸了什麼包,導致yum執行報錯狀況:

系統版本:Red Hat Enterprise Linux Server release 6.2 (Santiago)

核心版本:2.6.32-220.el6.x86_64

報錯情況:

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

2

3

4

5

6

7

8

1、檢視已安裝python的版本,可能是當前系統存在多個python導致

[[email protected]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

[[email protected]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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

1、刪除現有Python

[[email protected]test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##強制刪除已安裝程式及其關聯

[[email protected]test ~]# whereis python |xargs rm -frv ##刪除所有殘餘檔案 ##xargs,允許你對輸出執行其他某些命令

[[email protected]test ~]# whereis python ##驗證刪除,返回無結果

2、刪除現有的yum

[[email protected]test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

[[email protected]test ~]# whereis yum |xargs rm -frv

3、從http://mirrors.ustc.edu.cn/centos/6.4/os/x86_64/Packages/下載相應的包

python-2.6.6-36.el6.x86_64.rpm

python-devel-2.6.6-36.el6.x86_64.rpm

python-libs-2.6.6-36.el6.x86_64.rpm

python-pycurl-7.19.0-8.el6.x86_64.rpm

python-setuptools-0.6.10-3.el6.noarch.rpm

python-urlgrabber-3.9.1-8.el6.noarch.rpm  

python-iniparse-0.3.1-2.1.el6.noarch.rpm

rpm-python-4.8.0-32.el6.x86_64.rpm

yum-3.2.29-40.el6.centos.noarch.rpm

yum-metadata-parser-1.1.2-16.el6.x86_64.rpm

yum-utils-1.1.30-14.el6.noarch.rpm

yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm     

yum-plugin-protectbase-1.1.30-14.el6.noarch.rpm

yum-plugin-aliases-1.1.30-14.el6.noarch.rpm

yum-plugin-downloadonly-1.1.30-14.el6.noarch.rpm

由於源中版本會更新,具體請檢視URL中的版本再下載下來!

[[email protected]test ~]# rpm -Uvh --replacepkgs python*.rpm

[[email protected]test ~]# rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm

可能之間還需要zlib和zlib-devel包,根據情況下載並安裝!

三、執行python進行測試

1

2

3

4

5

6

7

[[email protected]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啦~