• ubuntu 22.04中安装python2


    001、系统

    root@ubuntu01:/home# hostnamectl
     Static hostname: ubuntu01
           Icon name: computer-vm
             Chassis: vm
          Machine ID: e6fb52b4c8414f29b06dc95d57b5846c
             Boot ID: 4ffb5c0e628241fe84425ca626565e00
      Virtualization: vmware
    Operating System: Ubuntu 22.04.1 LTS
              Kernel: Linux 5.15.0-47-generic
        Architecture: x86-64

    002、查看系统已安装的python版本

    root@ubuntu01:/home# ls /usr/bin/python*          ## 默认安装了python3
    /usr/bin/python3     /usr/bin/python3-futurize
    /usr/bin/python3.10  /usr/bin/python3-pasteurize

    003、调用python2测试

    root@ubuntu01:/home# python2
    Command 'python2' not found, but can be installed with:
    apt install python2

    004、查看是否配置了Python替代方案

    root@ubuntu01:/home# update-alternatives --list python
    update-alternatives: error: no alternatives for python

    005、安装python2

    root@ubuntu01:/home# apt install python2

    006、检查已安装的python版本

    root@ubuntu01:/home# ls /usr/bin/python*           ## 查看已安装的python版本
    /usr/bin/python2    /usr/bin/python3     /usr/bin/python3-futurize
    /usr/bin/python2.7  /usr/bin/python3.10  /usr/bin/python3-pasteurize

    007、分别调用python2和python3 测试

    root@ubuntu01:/home# python2 --version         ## python2
    Python 2.7.18
    root@ubuntu01:/home# python3 --version         ## python3
    Python 3.10.6

    008、查看是否配置了python替代方案

    root@ubuntu01:/home# update-alternatives --list python
    update-alternatives: error: no alternatives for python

    009、设置python替代方案

    root@ubuntu01:/home# update-alternatives --install /usr/bin/python python /usr/bin/python2 1  ## 将python2设置为1
    update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in auto mode
    root@ubuntu01:/home# update-alternatives --install /usr/bin/python python /usr/bin/python3 2  ## 将python3设置为2
    update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode

    010、查看设置的python替代方案是否成功

    root@ubuntu01:/home# update-alternatives --list python    ## 产看python替代方案
    /usr/bin/python2
    /usr/bin/python3

    011、如何切换版本

    root@ubuntu01:/home# update-alternatives --config python         ## 如何切换版本
    There are 2 choices for the alternative python (providing /usr/bin/python).
    
      Selection    Path              Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/python3   2         auto mode
      1            /usr/bin/python2   1         manual mode
      2            /usr/bin/python3   2         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 1      ## 此处选择1 python2
    update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode

    012、测试切换效果

    root@ubuntu01:/home# python --version

    参考:https://blog.csdn.net/ai1648410251/article/details/121224177

  • 相关阅读:
    MySQL热备脚本
    从库查看状态的时候显示“ Last_Error”
    Jenkins+svn+maven
    confluence的安装、备份和恢复(wiki)
    RAP在centos上的部署
    不停止MySQL服务的情况下修改root的密码
    给Linux装图形化界面
    大文件传输工具
    MySQL server PID file could not be found!
    find常见用法
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/16696065.html
Copyright © 2020-2023  润新知