在 CentOS 系统下运行 Python 脚本,你需要先确保已经安装了 Python。CentOS 7 默认安装的是 Python 2.x,而 CentOS 8 默认安装的是 Python 3.x。你可以使用以下命令检查 Python 是否已经安装以及其版本:
python --version
或者,如果你想检查 Python 3 的版本:
python3 --version
如果 Python 已经安装,你可以使用以下方法运行 Python 脚本:
python
命令运行 Python 2.x 脚本:python script.py
python3
命令运行 Python 3.x 脚本:python3 script.py
如果你的脚本文件名是 script.py
,请将其替换为实际的文件名。
如果你没有安装 Python,你可以使用以下命令安装:
对于 Python 2.x:
sudo yum install python
对于 Python 3.x:
sudo yum install python3
安装完成后,你可以按照上述方法运行 Python 脚本。