5

如何在 Ubuntu 和其他相关 Linux 中安装 Python 3.10

 1 year ago
source link: https://www.51cto.com/article/721619.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何在 Ubuntu 和其他相关 Linux 中安装 Python 3.10

作者:Arindam 2022-10-31 08:24:24
计划为工作安装 Python 3.10?以下是在 Ubuntu 和相关发行版中安装 Python 3.10 的方法。
f88444419f11ded10da0906fc8ef571ca38952.jpg

Python 3.10 于 2021 年 10 月 25 日发布,具有附加功能和更新。此版本带来了更好的错误消息处理、新的模式匹配功能、类型别名TypeAlias、用户定义的类型保护等。你可以在 ​​此处​​ 阅读发布重点。

在编写本指南时,大多数当前发行版都采用 Python 3.10。例如,Ubuntu 22.04 LTS 和 Fedora 36 默认都有 Python 3.10。

也就是说,如果你现在在任何不支持的版本中需要 Python 3.10,你可以使用 ​​下面的可靠 PPA​​ 在 Ubuntu 中安装最新的 Python 3.10。下面是方法。

如何在 Ubuntu 上安装 Python 3.10

此 PPA 可用于 Ubuntu 21.10、Ubuntu 21.04、Ubuntu 20.04 LTS、Ubuntu 18.04 LTS 和 Linux Mint 20.x、Elementary OS 6 和其他相关的基于 Ubuntu 的发行版。这些发行版大多数默认情况下不支持 3.10。

打开终端并添加以下 PPA:

sudo add-apt-repository ppa:deadsnakes/ppa

使用以下命令刷新缓存:

sudo apt update

并使用以下命令安装 Python 3.10:

sudo apt install python3.10

设置 Python 版本

将 Python 3.10 设置为默认值需要一些额外的步骤。如下。

警告:你的 Ubuntu 系统中的许多应用程序依赖于 Python 3.9 的库存版本。因此,请确保你的工作应用(例如 GIMP、GNOME 终端等)与 Python 3.10 兼容。所以,要小心。

快速提示: 如果要检查已安装的系统包中的哪些依赖于特定版本,请使用 ​​apt-cache​​ 命令的 ​​rdepends​​ 开关。在下面的示例中,我检查哪些已安装的包依赖于 Python 3.8。

apt-cache rdepends python3.8
[~]$ apt-cache rdepends python3.8
python3.8
Reverse Depends:
python3.8-dbg
virtualbox
python3.8-venv
python3.8-full
libpython3.8-testsuite
libglib2.0-tests
idle-python3.8
idle-python3.8
python3.8-minimal
python3.8-doc
python3.8-dev
python3.8-dbg
python3-uno
gedit
virtualbox
stimfit
python3.8-venv
python3-stfio
python3-escript-mpi
python3-escript
python3-csound
pitivi
obs-studio
liferea
libpython3.8-testsuite
libglib2.0-tests
kitty
kdevelop-python
idle-python3.8
idle-python3.8
rhythmbox-plugins
python3.8-minimal
python3.8-doc
python3.8-dev
python3
python3-uno
python3-all
cluster-glue
gedit
[~]$

使用 Python 3.10 作为默认 Python3

首先,使用终端中的以下命令检查当前默认版本。

python3 --version

使用 ​​update-alternatives​​ 创建指向 ​​python3​​ 的符号链接。

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2

并通过以下命令选择使用哪一个作为 ​​python3​​:

sudo update-alternatives --config python3
06beb7a34f5366cdbd64666284f19cb898f940.jpg

在 Ubuntu 中安装 Python 3.10

这就是所有步骤。现在,你可以开始在当前的 Ubuntu 版本中使用最新的 Python 进行工作/学习。你可以使用上述命令切换到库存版本并在任何时间更改版本号。

责任编辑:庞桂玉 来源: Linux中国

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK