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

相关推荐
CCPC不拿奖不改名5 小时前
虚拟机基础:在VMware WorkStation上安装Linux为容器化部署打基础
linux·运维·服务器·人工智能·milvus·知识库搭建·容器化部署
fjh19976 小时前
记一次奇怪的ssh公钥登录失败的情况
运维·ssh
一只自律的鸡7 小时前
【Linux系统编程】文件IO 函数篇
linux·linux系统编程
dinga198510268 小时前
linux上redis升级
linux·运维·redis
hzc09876543218 小时前
Linux系统下安装配置 Nginx 超详细图文教程_linux安装nginx
linux·服务器·nginx
匀泪9 小时前
云原生(nginx实验(2))
运维·nginx·云原生
RisunJan9 小时前
Linux命令-ltrace(用来跟踪进程调用库函数的情况)
linux·运维·服务器
阿乐艾官9 小时前
【 LVM 创建逻辑卷】
linux
予枫的编程笔记9 小时前
【Linux高级篇】搞定文件句柄+TIME_WAIT,Linux内核初步调优实操指南
linux·linux运维·ulimit·time_wait·sysctl.conf·内核调优·服务器优化
c***03239 小时前
linux centos8 安装redis 卸载redis
linux·运维·redis