用户工具

站点工具


linux:ubuntu:python3升级

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
linux:ubuntu:python3升级 [2020/09/22 08:33] zhangguolinux:ubuntu:python3升级 [2023/03/17 10:12] (当前版本) – 外部编辑 127.0.0.1
行 5: 行 5:
 在 Ubuntu 16.04 中,python3 的默认版本为 Python 3.5.2 在 Ubuntu 16.04 中,python3 的默认版本为 Python 3.5.2
  
-像类似''print(f'hello')''这样的语句3.5还不支持,需要至少升级到3.6+像类似''print(f'hello')''这样的语句3.5还不支持,需要至少升级到3.6。<color #ed1c24>本文以在 Ubuntu 16.04 中安装为例,方法同样适用于 Ubuntu 18.04 。</color>
  
 +
 +不太建议对系统的python版本进行升级,而是最好采用直接安装anaconda3的方式,这样没有依赖问题,免于折腾。
 ===== - 通过 Apt 安装 ===== ===== - 通过 Apt 安装 =====
 Ubuntu 官方 apt 库中还未收录 python 3.8,这里使用 deadsnakes PPA 库安装。 Ubuntu 官方 apt 库中还未收录 python 3.8,这里使用 deadsnakes PPA 库安装。
 +
 +==== - 安装依赖包 ====
 +<code>
 +$ sudo apt update
 +$ sudo apt install software-properties-common
 +</code>
 +
 +
  
 ==== - 添加源 ==== ==== - 添加源 ====
行 28: 行 38:
  
 ===== - 配置 python3.8 为系统默认 python3 ===== ===== - 配置 python3.8 为系统默认 python3 =====
 +
 +==== - 将 python 各版本添加到 update-alternatives ====
 +<code>
 +$ 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
 +</code>
 +
 +==== - 配置 python3 默认指向 python3.8 ====
 +
 +<code>
 +$ 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
 +  /usr/bin/python3.5 2  manual mode
 +  /usr/bin/python3.8 1  manual mode
 + 
 +Press <enter> to keep the current choice[*], or type selection number: 2
 +</code>
 +
 +
 +==== - 测试 python 版本 ====
 +
 +<code>
 +$ python3 -V
 +
 +Python 3.8.2
 +</code>
  
  
  
linux/ubuntu/python3升级.1600734821.txt.gz · 最后更改: 2023/03/17 10:12 (外部编辑)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki