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

相关推荐

  1. CentOS 系统升级 Python 版本

    2024-01-03 10:26:06       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-03 10:26:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-03 10:26:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-03 10:26:06       87 阅读
  4. Python语言-面向对象

    2024-01-03 10:26:06       96 阅读

热门阅读

  1. PWA应用总结

    2024-01-03 10:26:06       62 阅读
  2. 计算机视觉 全教程目录

    2024-01-03 10:26:06       57 阅读
  3. Nacos的CAP定理

    2024-01-03 10:26:06       62 阅读
  4. 针对NPC客户端的升级(脚本执行)

    2024-01-03 10:26:06       62 阅读
  5. Qt学生信息管理系统(Qt+DataBase)

    2024-01-03 10:26:06       64 阅读
  6. Android 实现动态申请各项权限

    2024-01-03 10:26:06       64 阅读
  7. Python-位置限定参数

    2024-01-03 10:26:06       64 阅读
  8. 几个实用网站

    2024-01-03 10:26:06       61 阅读
  9. 阶段七-Bootstrap

    2024-01-03 10:26:06       58 阅读
  10. 阿里云和腾讯云2核2G3M服务器上传速度多少?

    2024-01-03 10:26:06       72 阅读