51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

安装python3模块时,yum命令无法执行

安装python3模块时,yum命令无法执行

/usr/bin/yum: line 2: import: command not found
/usr/bin/yum: line 3: try:: command not found
/usr/bin/yum: line 4: import: command not found
/usr/bin/yum: line 5: except: command not found
/usr/bin/yum: line 23: syntax error near unexpected token `('
/usr/bin/yum: line 23: `""" % (sys.exc_value, sys.version)'

原因:升级python3导致

解决方法:

1.查看yum版本:

rpm -qa |grep yum

2.查看Python版本

cd /usr/bin 目录下

ll python*

https://www.cnblogs.com/1111zhiping-tian/p/10759524.html

查看当前使用的python路径

/root/.pyenv/shims/python

造成yum出错的根本原因就是你动了python2的版本了,yum是要依赖python的,只要你动了(重装、删除等等)都会造成这个错误。网上有很多简单的解决办法都没用;

比如最多的是vim /usr/bin /yum 将第一行改成你 /usr/bin/pythonxxx
这种情况只适用于你新装的python与yum原本依赖的python版本并存的情况下 才有效
比如yum原本依赖python2.6 你装了python2.7 这时修改这第一行 成/usr/bin/python2.6是可以的
如果原本依赖的python版本没了,那就只能重新安装yum了;

  1. #替换以前的python默认版本(创建新的软连接)

cd /usr/bin/

rm -rf python

ln -s /usr/local/python27/bin/python2.7 ./python

ls -l # 查询 /usr/bin/ 软连接

以上方法依然没有 成功

最终方案:

wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
wget  http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm

下载后 安装:

rpm -ivh --force *.rpm --nodeps

然后我们测试一下:

找一个包随便安装一下:

yum install python-pip

到此就成功了。

赞(8)
未经允许不得转载:工具盒子 » 安装python3模块时,yum命令无法执行