温馨提示×

怎样检查Debian Python是否安装

小樊
43
2026-07-31 22:47:27
栏目: 编程语言

在 Debian 系统中,可以通过以下几种方式检查 Python 是否已安装 以及 版本信息


一、检查 Python 是否已安装

1. 检查 Python 3(推荐)

Debian 10 及以后版本默认使用 Python 3:

python3 --version

python3 -V

✅ 如果已安装,会显示类似:

Python 3.11.2

❌ 如果未安装,会提示:

command not found

2. 检查 Python 2(老系统)

部分旧系统可能还有 Python 2:

python2 --version

python --version

⚠️ 注意

  • Debian 11 及以后 默认不再安装 python 命令
  • python 命令可能不存在,不代表 Python 没装

二、查看系统中安装了哪些 Python 版本

1. 使用 which

which python3
which python

2. 查看所有已安装的 Python 可执行文件

ls /usr/bin/python*

示例输出:

/usr/bin/python3
/usr/bin/python3.11

三、使用 dpkg 检查是否通过 apt 安装

1. 查看 Python 3 包

dpkg -l | grep python3

2. 查看具体包是否安装

dpkg -s python3

四、使用 apt 检查

apt list --installed | grep python

五、进入 Python 交互式环境(验证是否可用)

python3

成功进入后显示:

Python 3.x.x ...
>>>

退出:

exit()

六、如果未安装,如何安装 Python 3

sudo apt update
sudo apt install python3

如需 pip:

sudo apt install python3-pip

总结

检查方式 命令
查看 Python 3 版本 python3 --version
查看 Python 路径 which python3
查看所有 Python ls /usr/bin/python*
查看安装包 `dpkg -l

如果你愿意,可以告诉我 Debian 版本号(如 Debian 11 / 12),我可以给你更精确的建议。

0