将 Ubuntu 16 和 18 上的 python 升级到最新 python3.8 的方法教程

作者:haiiiiiyun 时间:2022-12-16 07:50:17 

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

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

资源

How to Install Python 3.8 on Ubuntu 18.04

How to upgrade to python 3.7 on Ubuntu 18.10

来源:https://segmentfault.com/a/1190000021967408

标签:Ubuntu,16,18,python3.8
0
投稿

猜你喜欢

  • python网络编程学习笔记(10):webpy框架

    2022-07-10 05:43:14
  • Mootools 1.2教程(9)——输入过滤第二部分(字符串)

    2008-12-01 12:25:00
  • Firefox 3.5 新增加的支持(整理)

    2009-08-01 12:51:00
  • python中各种路径设置的方法详解

    2022-12-09 23:58:09
  • python中如何设置list步长

    2022-11-04 14:24:02
  • Python+OpenCV实战之拖拽虚拟方块的实现

    2023-08-28 15:02:58
  • js“树”读取xml数据源码

    2007-08-04 19:42:00
  • Mysql分库分表之后主键处理的几种方法

    2024-01-20 21:00:09
  • Python中字典和JSON互转操作实例

    2023-03-12 14:18:11
  • SQL Server数据库导入MySQL数据库体验

    2009-01-20 16:07:00
  • python jinja2模板的使用示例

    2023-08-11 05:12:12
  • ThinkPHP中url隐藏入口文件后接收alipay传值的方法

    2024-05-03 15:50:25
  • OpenCV Python实现拼图小游戏

    2021-07-30 18:10:34
  • Python实现socket非阻塞通讯功能示例

    2022-05-16 03:18:25
  • Python实现将MongoDB中的数据导入到MySQL

    2024-01-21 04:41:01
  • Python读取excel文件中带公式的值的实现

    2022-04-05 14:03:27
  • Django中URL视图函数的一些高级概念介绍

    2021-04-14 13:35:21
  • python SVD压缩图像的实现代码

    2023-04-18 18:23:30
  • Vue 使用 Mint UI 实现左滑删除效果CellSwipe

    2024-05-10 14:16:45
  • python扩展库numpy入门教程

    2022-05-05 14:28:05
  • asp之家 网络编程 m.aspxhome.com