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

相关推荐
Sarvartha5 分钟前
三目运算符
linux·服务器·前端
liangdabiao7 分钟前
乐高摩托车深度报告-致敬张雪夺冠 -基于llm-wiki技术自动化写文章的效果
运维·人工智能·自动化
vortex513 分钟前
Kali Linux 安装与使用 Code-OSS / VSCodium :VSCode 轻量替代
linux·运维·编辑器
GuokLiu26 分钟前
260502-Clawith-Docker安装过程
运维·docker·容器·claw
.柒宇.1 小时前
AI掘金头条项目部署实践指南
linux·运维·python·fastapi
budingxiaomoli1 小时前
多机部署,负载均衡-LoadBalancer
运维·spring cloud·负载均衡
JesseDev1 小时前
Docker lnmp环境快速搭建开箱即用
运维·docker·容器
zhangrelay2 小时前
Ubuntu 18.04 经典 / 有趣 / 实用 APT 软件清单
linux·笔记·学习·ubuntu
金牛IT2 小时前
Gogs 轻量级 Git 服务器搭建与使用
运维·服务器·git
不做无法实现的梦~2 小时前
linux怎么使用正点原子无线dap烧录器
linux·运维·postgresql