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即可正常

相关推荐
yenggd1 小时前
centos系统apache支持php配置
centos·php·apache
方渐鸿2 小时前
【2024】k8s集群 图文详细 部署安装使用(两万字)
java·运维·容器·kubernetes·k8s·运维开发·持续部署
我爱云计算2 小时前
K8S详解(5万字详细教程)
linux·运维·云原生·容器·kubernetes
明明跟你说过2 小时前
【k8s】资源限制管理:Namespace、Deployment与Pod的实践
运维·docker·云原生·容器·kubernetes·k8s
2301_794333915 小时前
实验室服务器配置|通过Docker实现Linux系统多用户隔离与安全防控
linux·服务器·docker·实验室
打码人的日常分享5 小时前
运维服务方案,运维巡检方案,运维安全保障方案文件
大数据·运维·安全·word·安全架构
荣光波比6 小时前
Nginx 实战系列(一)—— Web 核心概念、HTTP/HTTPS协议 与 Nginx 安装
linux·运维·服务器·nginx·云计算
武文斌776 小时前
单片机:DS18B20测温度、74HC595扩展芯片、8*8LED矩阵
运维·服务器·单片机·嵌入式硬件
fengfuyao9856 小时前
诊断并修复SSH连接Github时遇到的“connection closed“错误
运维·ssh·github
scugxl7 小时前
centos7 docker离线安装
运维·docker·容器