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

相关推荐
chinesegf2 小时前
清理docker残留镜像images
运维·docker·容器
江湖有缘2 小时前
基于华为openEuler系统部署Gitblit服务器
运维·服务器·华为
yuanmenghao2 小时前
Linux 性能实战 | 第 10 篇 CPU 缓存与内存访问延迟
linux·服务器·缓存·性能优化·自动驾驶·unix
EnglishJun2 小时前
Linux系统编程(二)---学习Linux系统函数
linux·运维·学习
小Pawn爷2 小时前
2.Docker的存储
运维·docker·容器
CaracalTiger2 小时前
OpenClaw-VSCode:在 VS Code 中通过 WebSocket 远程管理 OpenClaw 网关的完整方案
运维·ide·人工智能·vscode·websocket·开源·编辑器
qq_5470261792 小时前
LangChain 1.0 核心概念
运维·服务器·langchain
VekiSon2 小时前
Linux内核驱动——设备树原理与应用
linux·c语言·arm开发·嵌入式硬件
Trouvaille ~2 小时前
【Linux】进程间关系与守护进程详解:从进程组到作业控制到守护进程实现
linux·c++·操作系统·守护进程·作业·会话·进程组
生而为虫2 小时前
[Windows] 【浏览器自动化精灵V1.0】用Excel表格控制浏览器的自动化
运维·自动化