You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已知Python IDLE运行脚本方法,求命令提示符运行Python脚本的正确方式

如何从命令提示符(终端)运行Python脚本

你用run test.py命令失败是因为系统没有run这个执行Python脚本的命令,得调用Python解释器来运行,步骤如下:

  • 打开命令提示符(Windows)或终端(Linux/macOS)
  • 切换到你的test.py脚本所在的文件夹:
    • Windows示例:如果脚本在C:\Users\你的用户名\Desktop,输入cd C:\Users\你的用户名\Desktop
    • Linux/macOS示例:如果脚本在~/Desktop,输入cd ~/Desktop
  • 执行脚本,根据你的Python版本选择对应命令:
    • 若安装的是Python 3,输入 python3 test.py
    • Windows环境下如果只装了Python 3,也可以直接输入 python test.py
    • 部分Windows系统支持用 py test.py 自动调用对应版本的Python

你的测试脚本内容如下:

print("Hello World")
print("This is a test")
print(1+1)

内容的提问来源于stack exchange,提问作者user22988761

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 12:33:10