Ubuntu 不同版本预装(系统自带)的 Python 版本是不一样的,而且你自己可以安装任意版本的 Python(通过 apt、源码、pyenv 等)。
下面给你一个清晰的说明:
| Ubuntu 版本 | 默认 Python 3 版本 |
|---|---|
| Ubuntu 18.04 | Python 3.6 |
| Ubuntu 20.04 | Python 3.8 |
| Ubuntu 22.04 | Python 3.10 |
| Ubuntu 24.04 | Python 3.12 |
⚠️ 注意:
- Ubuntu 已不再预装 Python 2
- 系统Python用于系统工具,不建议直接升级或删除
通过 apt 可安装的常见版本(以 Ubuntu 22.04 为例):
sudo apt install python3.8
sudo apt install python3.9
sudo apt install python3.10
sudo apt install python3.11
deadsnakes PPA(非常常用)pyenv例如:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.12
python3 --version
lsb_release -a
如果你愿意,可以告诉我:
我可以给你最合适安装的 Python 版本建议。