centos 7.9 升级系统默认的python2.7到python 2.7.18

centos 7.9 升级系统默认的python2.7到python 2.7.18

备份旧版本

mv /usr/bin/python /usr/bin/python_2.7.5

下载新版本

Download Python | Python.org Python Release Python 2.7.18 | Python.org wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz

复制代码
cd /home/soft
tar -xzf Python-2.7.18.tgz
cd Python-2.7.18
mkdir /usr/local/python2.7.18/
./configure --prefix=/usr/local/python2.7.18
make && make install
​
####
​
ln -s /usr/local/python2.7.18/bin/python2.7 /usr/bin/python
ln -s /usr/local/python2.7.18/bin/python /usr/local/bin/python

centos的python升级安装完成。

安装 pip

复制代码
curl "https://bootstrap.pypa.io/pip/2.7/get-pip.py" -o "get-pip.py"
​
python get-pip.py
​
ln -s /usr/local/python2.7.18/bin/pip /usr/bin/pip
centos中yum指令报错No module named yum解决
复制代码
vi /usr/bin/yum
#!/usr/bin/python2.7
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
​
   %s
​
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:
%s
​
If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
​
""" % (sys.exc_value, sys.version)
    sys.exit(1)
​
sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
    print >> sys.stderr, "\n\nExiting on user cancel."
    sys.exit(1)
​

将上述文件第一行

复制代码
#!/usr/bin/python 修改为:
#!/usr/bin/python2.7

重新yum即可正常

相关推荐
Calebbbbb9 分钟前
使用 Android Emulator 针对 AOSP 单测编译运行并检查覆盖率的完整实践
android·linux·安卓
童话的守望者18 分钟前
matrix-breakout-2-morpheus靶机通关
linux·运维·服务器
Frank_refuel27 分钟前
Linux操作系统 -> 进程信号(上)
linux·运维·服务器
信创DevOps先锋42 分钟前
Gitee:中国DevOps生态的数字化转型引擎
运维·gitee·devops
一只专注api接口开发的技术猿1 小时前
商品详情API的SLA保障体系:监控告警、异常检测与自动化修复
运维·数据库·架构·自动化
嵌入式学不会不改名1 小时前
香橙派环境
linux·ubuntu
BS_Li1 小时前
【Linux网络编程】Socket编程UDP
linux·网络·udp
时光之源1 小时前
程序猿常用命令行(Linux、Windows、Powershell、CMD、conda、pip、apt)
linux·conda·pip
qing222222222 小时前
Linux:/var/log/journal 路径下文件不断增加导致根目录磁盘爆满
linux·运维·前端
lwx9148522 小时前
Linux-后台运行操作符&
linux·运维·服务器