mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
parent
86ca2714b0
commit
f682b7e071
@ -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
|
@ -1,182 +0,0 @@
|
|||||||
[#]: 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: " "
|
|
||||||
[#]: reviewer: " "
|
|
||||||
[#]: publisher: " "
|
|
||||||
[#]: url: " "
|
|
||||||
|
|
||||||
How to Install Python 3.11 in Ubuntu and Other Related Linux
|
|
||||||
======
|
|
||||||
|
|
||||||
**Planning to get Python 3.11 installed for your project work? Here’s how to install Python 3.11 in Ubuntu and related distros.**
|
|
||||||
|
|
||||||
![][1]
|
|
||||||
|
|
||||||
Python 3.11 was released on Oct 25, 2022, and claims to be 10-60% faster than the prior [Python 3.10][2] version.
|
|
||||||
|
|
||||||
As always, the feature and improvement list are significantly high in 3.11. Here’s a brief.
|
|
||||||
|
|
||||||
- Error tracebacks are not more definite, which gives you an exact statement that causes the error.
|
|
||||||
- Introduction of exception groups and new except* syntax
|
|
||||||
- You can add custom text in the base expression for better error handling in your code.
|
|
||||||
- Introduction of Variadic generic to allow array-like structure in numerical Python libraries )such as NumPy)
|
|
||||||
- Dictionary type TypedDict gets improvement where you can now specify whether individual dictionary items are mandatory or optional.
|
|
||||||
- Introduction of Self annotation, which allows classes to return their own type instance.
|
|
||||||
|
|
||||||
And many more, which you can read in detail on the official [3.11 highlights page][3].
|
|
||||||
|
|
||||||
### Current Python versions in Linux Distros
|
|
||||||
|
|
||||||
[Ubuntu 22.04 LTS][4] have Python 3.10, whereas the recently released [Ubuntu 22.10 Kinetic Kudu][5] also have the same. However, Kinetick Kudu will probably feature 3.11 within a few weeks.
|
|
||||||
|
|
||||||
Also, [Fedora 37][6] (planned for Nov 1) already has the Python 3.11 RC2 and will get the version.
|
|
||||||
|
|
||||||
So, if you are running Ubuntu 22.04 LTS, [Linux Mint 21][7] or any Ubuntu-LTS-based distros, here’s how you can install Python 3.11 via a PPA.
|
|
||||||
|
|
||||||
**Note**: Use this method with caution. Make sure you know what you are doing because replacing the base Python version of a Linux distribution may cause an unstable system. Many default applications and packages depend on the 3.10 version.
|
|
||||||
|
|
||||||
### How to install Python 3.11 in Ubuntu and related distros
|
|
||||||
|
|
||||||
- Open a terminal prompt and add the following PPA.
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
|
||||||
```
|
|
||||||
|
|
||||||
- Refresh the cache using the below command.
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo apt update
|
|
||||||
```
|
|
||||||
|
|
||||||
- And install Python 3.11 using the below command.
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo apt install python3.11
|
|
||||||
```
|
|
||||||
|
|
||||||
![Install Python 3.11 in Ubuntu 22.04 LTS][8]
|
|
||||||
|
|
||||||
Install Python 3.11 in Ubuntu 22.04 LTS
|
|
||||||
|
|
||||||
### Set Default Python Versions
|
|
||||||
|
|
||||||
In theory, you can install multiple versions of Python in Linux distros, but the default can only be one version. Setting up Python 3.11 as default requires some additional steps. Follow along.
|
|
||||||
|
|
||||||
However, before you do that, make sure you know which applications depend on Python 3.10. You can easily find it out using `apt-cache rdepends` command as below.
|
|
||||||
|
|
||||||
```
|
|
||||||
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
|
|
||||||
virtualbox
|
|
||||||
python3.10-venv
|
|
||||||
python3.10-full
|
|
||||||
libpython3.10-testsuite
|
|
||||||
kitty
|
|
||||||
idle-python3.10
|
|
||||||
idle-python3.10
|
|
||||||
python3.10-minimal
|
|
||||||
python3.10-doc
|
|
||||||
python3.10-dev
|
|
||||||
python3.10-dbg
|
|
||||||
python3-uno
|
|
||||||
python3-all
|
|
||||||
python3.10-dbg
|
|
||||||
virtualbox
|
|
||||||
stimfit
|
|
||||||
python3.10-venv
|
|
||||||
python3.10-full
|
|
||||||
python3-stfio
|
|
||||||
python3-escript-mpi
|
|
||||||
python3-escript
|
|
||||||
python3-csound
|
|
||||||
plasma-firewall
|
|
||||||
pitivi
|
|
||||||
obs-studio
|
|
||||||
liferea
|
|
||||||
libpython3.10-testsuite
|
|
||||||
libglib2.0-tests
|
|
||||||
kitty
|
|
||||||
idle-python3.10
|
|
||||||
idle-python3.10
|
|
||||||
cluster-glue
|
|
||||||
atac
|
|
||||||
rhythmbox-plugins
|
|
||||||
python3.10-minimal
|
|
||||||
python3.10-doc
|
|
||||||
python3.10-dev
|
|
||||||
python3
|
|
||||||
python3-uno
|
|
||||||
python3-all
|
|
||||||
gedit
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Use Python 3.11 as the default Python3
|
|
||||||
|
|
||||||
- First, check the current default version using the below command from the terminal.
|
|
||||||
|
|
||||||
```
|
|
||||||
python3 --version
|
|
||||||
```
|
|
||||||
|
|
||||||
- Use `update-alternatives` to create symbolic links to `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
|
|
||||||
```
|
|
||||||
|
|
||||||
- And choose which one to use as Python3 via the command:
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo update-alternatives --config python3
|
|
||||||
```
|
|
||||||
|
|
||||||
![Setting up default python version to 3.11][9]
|
|
||||||
|
|
||||||
Setting up default python version to 3.11
|
|
||||||
|
|
||||||
Now you can start using the latest Python in your current Ubuntu version for your work/study. You switch to the stock version using the above commands and change the versions at any time.
|
|
||||||
|
|
||||||
If you switch to 3.11 using the above install method, then make sure you check all the necessary apps to see whether they are working fine.
|
|
||||||
|
|
||||||
Finally, do let me know in the comment box if you run into problems.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://www.debugpoint.com/install-python-3-11-ubuntu/
|
|
||||||
|
|
||||||
作者:[Arindam][a]
|
|
||||||
选题:[lkxed][b]
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [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
|
|
Loading…
Reference in New Issue
Block a user