升级 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

  • 11
    点赞
  • 76
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值