温馨提示×

Ubuntu 中 Python 安装后如何启动

小樊
36
2025-12-24 09:47:39
栏目: 编程语言

在 Ubuntu 中,Python 通常已经预装了

  1. 打开终端(快捷键:Ctrl + Alt + T)

  2. 首先,检查 Python 是否已经安装以及其版本。在终端中输入以下命令:

python --version

或者,如果你想检查 Python 3 的版本,请输入:

python3 --version

如果 Python 已经安装,你将看到相应的版本号。如果没有安装,你可以使用以下命令来安装 Python:

对于 Python 2.x(不推荐,因为 Python 2 已经停止支持):

sudo apt-get update
sudo apt-get install python

对于 Python 3.x:

sudo apt-get update
sudo apt-get install python3
  1. 如果你想运行 Python 脚本,可以在终端中使用以下命令:

对于 Python 2.x:

python script.py

对于 Python 3.x:

python3 script.py

script.py 替换为你要运行的 Python 脚本的文件名。

  1. 如果你想启动 Python 交互式解释器,可以在终端中输入以下命令:

对于 Python 2.x:

python

对于 Python 3.x:

python3

这将打开一个交互式环境,你可以在其中输入 Python 代码并立即查看结果。要退出交互式解释器,请输入 exit() 或按 Ctrl + D

0