如何检查 Ubuntu Python 是否安装成功

371
2025/4/13 18:32:16
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

要检查Ubuntu上是否安装了Python,您可以打开终端(快捷键:Ctrl + Alt + T),然后输入以下命令:

python --version

或者

python3 --version

如果Python已安装,您将看到类似以下的输出,显示Python的版本号:

Python 3.8.5

如果没有安装Python,您将看到一个错误消息,类似于:

python: can't open file '/usr/bin/python': [Errno 2] No such file or directory

或者

python3: can't open file '/usr/bin/python3': [Errno 2] No such file or directory

在这种情况下,您需要安装Python。对于大多数Ubuntu版本,Python 3是默认安装的。如果您需要安装Python 2,可以使用以下命令:

sudo apt-get update
sudo apt-get install python2

请注意,Python 2已经在2020年1月1日停止支持,因此建议您使用Python 3。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: filezilla连接ubuntu时断开怎么办