mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-09-04 04:32:49 +08:00
@@ -0,0 +1,142 @@
|
||||
[#]: subject: "How to Install Python 3.11 in Ubuntu and Other Related Linux"
|
||||
[#]: via: "https://www.debugpoint.com/install-python-3-11-ubuntu/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "wxy"
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: url: "https://linux.cn/article-15230-1.html"
|
||||
|
||||
如何在 Ubuntu 等 Linux 中安装 Python 3.11
|
||||
======
|
||||
|
||||
> 打算为你的项目开发工作安装 Python 3.11?下面是如何在 Ubuntu 等发行版中安装 Python 3.11 的方法。
|
||||
|
||||
![][1]
|
||||
|
||||
Python 3.11 于 2022 年 10 月 25 日发布,并声称比之前的 [Python 3.10][2] 版本快 10% - 60%。
|
||||
|
||||
一如既往,3.11 中的功能和改进列表明显较多。下面是一个简介:
|
||||
|
||||
- 错误回溯更明确,可以指出导致错误的确切语句。
|
||||
- 引入异常组和新的 except* 语法。
|
||||
- 你可以在基础表达式中添加自定义文本,以便在你的代码中更好地处理错误。
|
||||
- 引入 Variadic 泛型,允许在 Python 数值库(如 NumPy)中使用类似数组的结构。
|
||||
- 字典类型 TypedDict 得到了改进,现在你可以指定个别字典项目是必须的还是可选的。
|
||||
- 引入了 Self 注解,允许类返回它们自己的类型实例。
|
||||
|
||||
还有很多,你可以在官方的 [3.11 亮点页面][3] 上详细了解。
|
||||
|
||||
### Linux 发行版中的当前 Python 版本
|
||||
|
||||
[Ubuntu 22.04 LTS][4] 带有 Python 3.10,而最近发布的 [Ubuntu 22.10 Kinetic Kudu][5] 也是同样的版本。然而, Kinetick Kudu 可能会在几周内采用 3.11。
|
||||
|
||||
另外,[Fedora 37][6] 已经有了 Python 3.11 RC2,并将提供该版本。
|
||||
|
||||
所以,如果你正在运行 Ubuntu 22.04 LTS、[Linux Mint 21][7] 或任何基于 Ubuntu-LTS 的发行版,这里是你如何通过 PPA 安装 Python 3.11 的方法。
|
||||
|
||||
**注意**:谨慎地使用这个方法。确保你知道你在做什么,因为替换 Linux 发行版的基础 Python 版本可能会导致系统不稳定。许多默认的应用程序和软件包都依赖于 3.10 版本。
|
||||
|
||||
### 如何在 Ubuntu 和相关发行版中安装 Python 3.11
|
||||
|
||||
打开终端提示,添加以下 PPA:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
||||
```
|
||||
|
||||
使用下面的命令刷新缓存:
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
并使用下面的命令安装 Python 3.11:
|
||||
|
||||
```
|
||||
sudo apt install python3.11
|
||||
```
|
||||
|
||||
![在 Ubuntu 22.04 LTS 中安装 Python 3.11][8]
|
||||
|
||||
### 设置默认的 Python 版本
|
||||
|
||||
理论上,你可以在 Linux 发行版中安装多个版本的 Python,但只能默认一个版本。将 Python 3.11 设置为默认版本需要一些额外的步骤。请跟我做。
|
||||
|
||||
然而,在这之前,请确保你知道哪些应用程序依赖于 Python 3.10。你可以使用 `apt-cache rdepends` 命令轻松地找到它,如下所示:
|
||||
|
||||
```
|
||||
debugpoint@debugpoint-22-04:~$ apt-cache rdepends python3.10
|
||||
python3.10
|
||||
Reverse Depends:
|
||||
python3.10-dbg
|
||||
python3.10-venv
|
||||
python3.10-full
|
||||
libpython3.10-testsuite
|
||||
idle-python3.10
|
||||
idle-python3.10
|
||||
python3.10-minimal
|
||||
python3.10-doc
|
||||
python3.10-dev
|
||||
python3
|
||||
[截断]
|
||||
python3
|
||||
python3-uno
|
||||
python3-all
|
||||
gedit
|
||||
```
|
||||
|
||||
#### 使用 Python 3.11 作为默认的 Python3
|
||||
|
||||
首先,从终端使用以下命令检查当前的默认版本:
|
||||
|
||||
```
|
||||
python3 --version
|
||||
```
|
||||
|
||||
使用 `update-alternatives` 来创建 `python3` 的符号链接:
|
||||
|
||||
```
|
||||
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
|
||||
```
|
||||
|
||||
```
|
||||
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
|
||||
```
|
||||
|
||||
并通过命令选择哪一个作为 Python3 使用:
|
||||
|
||||
```
|
||||
sudo update-alternatives --config python3
|
||||
```
|
||||
|
||||
![设置默认的 Python 版本为 3.11][9]
|
||||
|
||||
现在你可以开始在你当前的 Ubuntu 版本中使用最新的 Python 来进行工作/学习了。你可以使用上述命令切换到库存版本,并随时改变版本。
|
||||
|
||||
如果你使用上述安装方法切换到 3.11,那么请确保你检查所有必要的应用程序,看它们是否工作正常。
|
||||
|
||||
最后,如果你遇到问题,请在评论区告诉我。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/install-python-3-11-ubuntu/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.debugpoint.com/wp-content/uploads/2022/10/py3112204-1024x576.jpg
|
||||
[2]: https://www.debugpoint.com/install-python-3-10-ubuntu/
|
||||
[3]: https://docs.python.org/3.11/whatsnew/3.11.html
|
||||
[4]: https://www.debugpoint.com/ubuntu-22-04-review/
|
||||
[5]: https://www.debugpoint.com/ubuntu-22-10/
|
||||
[6]: https://www.debugpoint.com/fedora-37/
|
||||
[7]: https://www.debugpoint.com/linux-mint-21-review/
|
||||
[8]: https://www.debugpoint.com/wp-content/uploads/2022/10/Install-Python-3.11-in-Ubuntu-22.04-LTS.jpg
|
||||
[9]: https://www.debugpoint.com/wp-content/uploads/2022/10/Setting-up-default-python-version-to-3.11.jpg
|
||||
Reference in New Issue
Block a user