温馨提示×

debian能跑python脚本吗

小樊
41
2026-10-19 18:25:45
栏目: 编程语言

可以的。Debian 完全可以运行 Python 脚本,而且大多数 Debian 系统本身就自带 Python。

1. 检查是否已安装 Python

在终端中执行:

python3 --version

如果显示类似 Python 3.11.2 的版本号,说明已经安装。

如果没有安装,可以用 apt 安装:

sudo apt update
sudo apt install python3

2. 写一个简单脚本

例如创建 hello.py:

print("Hello Debian")

3. 运行 Python 脚本

方式一:直接用 python3 运行

python3 hello.py

方式二:作为可执行脚本运行 在脚本第一行加上:

#!/usr/bin/env python3

然后赋予执行权限:

chmod +x hello.py
./hello.py

4. 补充说明

  • Debian 通常 默认只有 python3,没有 python 命令(这是正常的)
  • 可以用 pip3 安装第三方库:
    sudo apt install python3-pip
    pip3 install requests
    

如果你有具体需求(比如开机自启、定时任务、虚拟环境、GUI 脚本等),我可以继续帮你说明。

0 踩