CentOS 7 python2.7 卸载并重新安装

平台环境

Linux 版本为CentOS 7.6

[root@localhost Packages]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

问题描述

[root@localhost python]# yum -y install python-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirror.lzu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package python-devel.x86_64 0:2.7.5-76.el7 will be installed
--> Processing Dependency: python(x86-64) = 2.7.5-76.el7 for package: python-devel-2.7.5-76.el7.x86_64
--> Finished Dependency Resolution
Error: Package: python-devel-2.7.5-76.el7.x86_64 (rhel-source)
           Requires: python(x86-64) = 2.7.5-76.el7
           Installed: python-2.7.5-86.el7.x86_64 (@rhel-source)
               python(x86-64) = 2.7.5-86.el7
           Available: python-2.7.5-76.el7.x86_64 (rhel-source)
               python(x86-64) = 2.7.5-76.el7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

提示已经安装了python-2.7.5-86.el7.x86_64,但是需要 python-2.7.5-76.el7.x86_64 ,差异是一个小的迭代版本。

先是尝试直接删除已经安装的,不过提示下面错误:

[root@localhost python]# rpm -e python-2.7.5-86.el7.x86_64
error: Failed dependencies:
        python >= 2.2 is needed by (installed) pyxattr-0.5.1-5.el7.x86_64
        python >= 2.4 is needed by (installed) yum-3.4.3-161.el7.centos.noarch
        python is needed by (installed) authconfig-6.2.8-30.el7.x86_64
        python is needed by (installed) pykickstart-1.99.66.21-1.el7.noarch
        python >= 2.1 is needed by (installed) createrepo-0.9.9-28.el7.noarch

后面采用了直接忽略错误的方式:

[root@localhost python]# rpm -ev python-2.7.5-86.el7.x86_64 --nodeps
Preparing packages...
python-2.7.5-86.el7.x86_64
[root@localhost python]#

不料,结果又出现了新的问题:

[root@localhost python]# yum -y install python-devel
bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
[root@localhost python]# yum -y install python
bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

解决过程

删除现有 python

[root@localhost python]# rpm -qa|grep python | xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@localhost python]# whereis python | xargs rm -frv      ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@localhost python]# whereis python                      ##验证删除,返回无结果

删除现有的 yum

[root@localhost python]# rpm -qa | grep yum | xargs rpm -ev --allmatches --nodeps
[root@localhost python]# whereis yum | xargs rm -frv

下载相应 RPM 包

下载路径:
https://vault.centos.org/7.6.1810/os/x86_64/Packages/

注意核对自己CentOS( Linux) 版本,查看方式如下:

[root@localhost Packages]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

所需安装包分别如下:

wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm

wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm

安装python

建议使用 --nodeps --force,即不考虑依赖包,强制安装。

[root@localhost python]# rpm -ivh python-* rpm-python-*
warning: python-2.7.5-76.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
        python-backports-ssl_match_hostname is needed by python-setuptools-0.9.8-7.el7.noarch

[root@localhost python]# rpm -ivh python-*   rpm-python-* --nodeps --force
warning: python-2.7.5-76.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:python-libs-2.7.5-76.el7         ################################# [ 13%]

安装yum

[root@localhost python]# rpm -ivh yum-*
warning: yum-3.4.3-161.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
        libxml2-python is needed by yum-utils-1.1.31-50.el7.noarch
        python-kitchen is needed by yum-utils-1.1.31-50.el7.noarch

[root@localhost python]# rpm -ivh yum-* --nodeps --force
warning: yum-3.4.3-161.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 17%]
   2:yum-plugin-fastestmirror-1.1.31-5################################# [ 33%]
   3:yum-3.4.3-161.el7.centos         ################################# [ 50%]
   4:yum-utils-1.1.31-50.el7          ################################# [ 67%]
   5:yum-plugin-aliases-1.1.31-50.el7 ################################# [ 83%]
   6:yum-plugin-protectbase-1.1.31-50.################################# [100%]
[root@localhost python]#

你可能感兴趣的:(centos,linux)