升级 Ubuntu上的 python版本

1. 不要卸载Ubuntu自带的Python2.7和Python3.5,直接安装新版本的Python,然后修改默认的Python软链接即可。

2.安装Python3.8

  • 1) 安装依赖包
  • $ sudo apt update

    $ sudo apt install software-properties-common

  • 2)添加 deadsnakes PPA 源
  • $ sudo add-apt-repository ppa:deadsnakes/ppa

    Press Enter to continue

  • 3) 安装 python 3.8
  • $ sudo apt install python3.8

    报错:

    E: Unable to locate package python3.8
    E: Couldn't find any package by glob 'python3.8'
    E: Couldn't find any package by regex 'python3.8'

    解决方法:

    $ sudo apt-get update

    $ sudo apt install python3.8   //成功安装

    $ python3.8 –version

    Python 3.8.9

    3.采用update-alternatives 切换版本

  • 3.1 查看update-alternatives的帮助信息:update-alternatives –help
  • 3.2 查看有没有python可选项:update-alternatives –display python
  • 3.3 如果没有,输入下面的命令建立python可选项
  •   sudo update-alternatives –install /usr/bin/python python /usr/bin/python2.7 2

      sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.5 1

           sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.8 3

  • 3.4 切换python版本:sudo update-alternatives –config python
  • There are 3 choices for the alternative python (providing /usr/bin/python).
    
      Selection    Path                Priority   Status
    ------------------------------------------------------------
      0            /usr/bin/python3.8   3         auto mode
      1            /usr/bin/python2.7   2         manual mode
    * 2            /usr/bin/python3.5   1         manual mode
      3            /usr/bin/python3.8   3         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 3

    来源:一棵树是码农

    物联沃分享整理
    物联沃-IOTWORD物联网 » 升级 Ubuntu上的 python版本

    发表评论