温馨提示×

debian怎么运行python脚本

小樊
42
2026-10-08 01:32:19
栏目: 编程语言

在 Debian 上运行 Python 脚本一般步骤如下:

1. 确认是否安装 Python

python3 --version

如果没安装:

sudo apt update
sudo apt install python3

2. 编写 Python 脚本

例如创建一个文件 hello.py:

nano hello.py

内容:

print("Hello Debian")

3. 运行 Python 脚本

方法一:直接用 python3 运行

python3 hello.py

方法二:赋予可执行权限(推荐)

在脚本第一行加:

#!/usr/bin/env python3

然后:

chmod +x hello.py
./hello.py

4. 常用补充

  • 安装依赖:
pip3 install 包名
  • 使用虚拟环境:
python3 -m venv venv
source venv/bin/activate

如果你是 开机自启 / 后台运行 / 服务方式运行,也可以告诉我,我可以给你 systemd 示例。

0 踩