在 Ubuntu 上查看 Python 版本,可以通过以下几种方法:
打开终端:
Ctrl + Alt + T 打开终端。输入命令:
python --version 或 python3 --version 并按回车键。
python 命令通常指向 Python 2.x(如果已安装)。python3 命令指向 Python 3.x(通常是默认安装的版本)。python --version
# 或者
python3 --version
这将显示当前安装的 Python 版本号。
which 命令打开终端。
输入命令:
which python 或 which python3 并按回车键。which python
# 或者
which python3
这将显示 Python 可执行文件的路径,例如 /usr/bin/python3。
type 命令打开终端。
输入命令:
type python 或 type python3 并按回车键。type python
# 或者
type python3
这将显示 Python 的类型和路径。
pyenv 管理多个 Python 版本如果你使用 pyenv 来管理多个 Python 版本,可以通过以下命令查看当前激活的版本:
打开终端。
输入命令:
pyenv version 并按回车键。pyenv version
这将显示当前激活的 Python 版本。
python 命令可能默认指向 Python 2.x,而 python3 命令指向 Python 3.x。因此,建议使用 python3 来确保使用的是 Python 3.x 版本。pyenv 来轻松切换和管理这些版本。通过以上方法,你应该能够轻松查看 Ubuntu 上安装的 Python 版本。