如何将 Ubuntu 16 和 18 上的 python 升级到最新 3.8 版

转载:原文链接https://segmentfault.com/a/1190000021967408

1. 概述

本文记录在 Ubuntu 16.04 上将 python 升级为 3.8 版本,并配置为系统默认 python3 的过程。

在 Ubuntu 16.04 中,python3 的默认版本为 3.5:

$ python3 -V

Python 3.5.2

本文以在 Ubuntu 16.04 中安装为例,方法同样适用于 Ubuntu 18.04 。

2. 通过 Apt 安装

Ubuntu 官方 apt 库中还未收录 python 3.8,这里使用 deadsnakes PPA 库安装。

2.1. 安装依赖包

$ sudo apt update

$ sudo apt install software-properties-common

2.2. 添加 deadsnakes PPA 源

$ sudo add-apt-repository ppa:deadsnakes/ppa

Press [ENTER] to continue or Ctrl-c to cancel adding it.

2.3. 安装 python 3.8

$ sudo apt install python3.8

$ python3.8 -V

Python 3.8.2

3. 配置 python3.8 为系统默认 python3

修改默认 python3 会导致打不开 Terminal 等各种问题,解决方法见 Ubuntu16.04TLS 中终端(Terminal)无法打开的解决办法

3.1. 将 python 各版本添加到 update-alternatives

$ which python3.8

/usr/bin/python3.8

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

$ which python3.5

/usr/bin/python3.5

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 2

3.2. 配置 python3 默认指向 python3.8

$ sudo update-alternatives --config python3

There are 2 choices for the alternative python3 (providing /usr/bin/python3).

Selection Path Priority Status

------------------------------------------------------------

* 0 /usr/bin/python3.5 2 auto mode

1 /usr/bin/python3.5 2 manual mode

2 /usr/bin/python3.8 1 manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

选择/输入 2, 回车。

3.3 测试 python 版本

$ python3 -V

Python 3.8.2

资源

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值