温馨提示×

如何检查Debian的Python版本

小樊
35
2026-07-17 10:53:56
栏目: 编程语言

在 Debian 系统中,可以通过以下几种方式检查 Python 版本:

1. 检查默认 Python 版本

python --version

python -V

⚠️ 注意:在较新的 Debian(如 Debian 11+)中,python 命令可能默认不存在,而是使用 python3


2. 检查 Python 3 版本(推荐)

python3 --version

3. 查看系统中已安装的所有 Python 版本

ls /usr/bin/python*

dpkg -l | grep python

4. 使用 which 查看 Python 路径

which python3

5. 进入 Python 交互式环境查看

python3

进入后输入:

import sys
sys.version

退出:

exit()

6. 检查系统默认 Python 指向(Debian 特有)

update-alternatives --list python

update-alternatives --display python

常见情况说明

  • Debian 10(Buster)及以后版本 默认不再提供 python 命令
  • 系统工具通常使用 python3
  • 不建议强行把 python 指向 python3,避免破坏系统组件

如果你需要,我也可以帮你判断 该用 python 还是 python3,或者 如何安装指定版本

0