这两天在搭建openstack,话说这个真锻炼人!系统使用centos7.9,在安装pip的时候,提示python2版本低,需要升级到python3。

当时没多想,就直接卸载python2安装了python3,结果出来发现apache无法启动了!其中的模块mod_wsgi.so导致了apache无法启动,在想着怎么从新安装模块,又发现yum无法使用了!!!

自己学艺不精,才知道yum是由python2写的,由于python2和python3语法不兼容,如果系统中默认的python为python3则会导致这一现象。

image.png

没办法只能从新安装python2,之前卸载可是非常的干净,只能手动安装依赖了!

先贡献一下卸载python和yum的方法,大家可以试试!感受一下绝望!玩得开心!

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

1.安装python

1.1 下载tar包

wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz

1.2 安装python2.7.5

下载后,解压压缩包,进入文件编译软件。

tar -zxvf Python-2.7.5.tgz
cd Python-2.7.5
./configure --prefix=/usr/local/python27
make&&make install

也可以在configure之后执行 make altinstall 来防止替换掉默认的python版本

1.3 测试安装

/usr/local/python27/bin/python 

image.png

1.4 设置软件链接

ln -s /usr/local/python27/bin/python /usr/bin/python27

以后就可以直接使用 python27来使用2.7.5版本了

1.5 设置为默认的版本

保存老版本

mv /usr/bin/python /usr/bin/python-old

设置成默认

ln -s /usr/local/python27/bin/python /usr/bin/python

我的情况是里面python3需要设置成默认,因此在/usr/bin/yum中设置版本为python27

image.png

image.png

2.安装python2依赖

安装完后,yum依然无法使用。报错如下:

image.png /usr/local/bin/python3.8

查了下是依赖都卸载了,所以无法使用,只能手动解决了!

2.1 下载rpm包

或者直接在官方址找了:https://vault.centos.org/7.8.2003/os/x86_64/Packages/
这个已经是centos7官方最新的终结版本了。

下面是我已经找好的。

python2.7.5的依赖:
但是没想到,在清华镜像站还找到了更新的。
清华镜像站

wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-rpm-macros-3-34.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-srpm-macros-3-34.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python2-rpm-macros-3-34.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/libxml2-2.9.1-6.el7.5.i686.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/libxml2-2.9.1-6.el7.5.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.5.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-rhn-plugin-2.0.1-10.el7.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm

2.2 安装软件包

安装顺序:(试了很多遍,严格按顺序执行!那你想折腾我也不拦着!)

python-libs-2.7.5-89.el7.x86_64.rpm
python-2.7.5-89.el7.x86_64.rpm
python-srpm-macros-3-34.el7.noarch.rpm
python-rpm-macros-3-34.el7.noarch.rpm
python2-rpm-macros-3-34.el7.noarch.rpm
python-devel-2.7.5-89.el7.x86_64.rpm 
python-iniparse-0.4-9.el7.noarch.rpm
python-pycurl-7.19.0-19.el7.x86_64.rpm
python-urlgrabber-3.10-10.el7.noarch.rpm
rpm-python-4.11.3-45.el7.x86_64.rpm
python-backports-1.0-8.el7.x86_64.rpm
python-ipaddress-1.0.16-2.el7.noarch.rpm
python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-chardet-2.2.1-3.el7.noarch.rpm
python-kitchen-1.1.1-5.el7.noarch.rpm
libxml2-2.9.1-6.el7.5.x86_64.rpm
libxml2-python-2.9.1-6.el7.5.x86_64.rpm

image.png
image.png

yum的安装:

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-3.4.3-168.el7.centos.noarch.rpm                      (需要强制安装 加参数 --nodeps)
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm


yum-utils-1.1.31-54.el7_8.noarch.rpm
yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
yum-updateonboot-1.1.31-54.el7_8.noarch.rpm

image.png
image.png

这个安装的过程很爽!最后apache的问题也解决了!

image.png

这次最大的收获,就是破后而立,之前折腾了很久,装了python2 python3 想着怎那么能好,结果就是好不了,最后全卸载了,从新装一次搞定!

Q.E.D.

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

只有把抱怨环境的情绪,化为上进的力量,才是成功的保证!