记一次linux7.3yum源失效问题
由于手贱升级python 导致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.7.5 (default, Nov 2 2021, 21:34:44)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
由于又手贱吧python 删了又装,根据CSDN 各种帖子都没整好
经过多种操作最终解决问题,操作开始
1.先看系统版本
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
2.根据系统版本下载对应python包
官网地址:https://www.python.org/downloads/
找一台跟自己系统版本一样的linux 查看python版本
[root@localhost ~]# python -V
Python 2.7.5
3.卸载当前系统python,yum依赖
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
whereis python |xargs rm -frv
whereis python
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
whereis yum |xargs rm -frv
4.重新下载安装对应系统的python版本
4.1.linux下安装
--- 安装依赖包
# cd /usr/local
# wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
# tar -xzvf Python-2.7.5.tgz
# cd Python-2.7.5
# ./configure --prefix=/usr/local/Python2.7.5 --enable-shared -enable-unicode=ucs4
# make
# make install
# python -V
4.2.python解释器指向python2.7.5
# which python
# cd /usr/bin
# rm python
# ln -s /usr/local/Python2.7.5/bin/python python
# python -V --执行报错
4.3.解决python -V执行报错
# cd /etc/ld.so.conf.d/
# echo "/usr/local/Python2.7.5/lib" > python2.7.conf
# ldconfig
# python -V
5.找一台yum好的服务器,注意是好的!
找一台yum功能完好的服务器, 系统版本和坏的一致,
没有就自己去搭建一台和自己系统版本一样的虚拟机
5.1.输入命令查找 site-packages 包路径
[root@localhost ~]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
>>>
[root@localhost ~]#
python
import sys
print sys.path
输入 ctrl+D 退出
5.2.将/usr/lib64/python2.7/site-packages’, ‘/usr/lib/python2.7/site-packages’ 两个路径下的文件全部打包下载
5.3.找到/usr/share/yum-cli 将这个目录下的文件全部下载
5.4.打包下载后,转回,我们yum坏的那台服务器,找到路径 /usr/local/Python2.7.5/lib/python2.7/site-packages
这里可以看到我们是对应目录是空的
将刚刚打包下载的site-packages 文件全部上传到这
5.5.将刚刚下载的/usr/share/yum-cli 上传到 /usr/share/yum-cli
查看/usr/share 目录 看看 有没有yum-cli 目录, 如果没有那就创建一个,将好的那台服务器的文件传过来, 如果有,那就吧里面文件全部删掉, 在上传好的那台服务器
6.最后 执行yum 完美解决, 最好的解决办法就是找一台好的,将他python 目录下的 site-packages 和/usr/share/yum-cli 文件直接复制到挂的那台
别整什么下载各种插件,rpm安装,都是假的,全都没用, ctrl c ctrl v ,将好服务器的ctrl c ctrl v 到坏的比什么都强 艹