在 Ubuntu 中,Python 通常已经预装了
打开终端(快捷键:Ctrl + Alt + T)
首先,检查 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
对于 Python 2.x:
python script.py
对于 Python 3.x:
python3 script.py
将 script.py 替换为你要运行的 Python 脚本的文件名。
对于 Python 2.x:
python
对于 Python 3.x:
python3
这将打开一个交互式环境,你可以在其中输入 Python 代码并立即查看结果。要退出交互式解释器,请输入 exit() 或按 Ctrl + D。