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

VS Code运行Python文件后终端显示>>>无法执行系统命令求助

解决VS Code运行Python后终端停留在交互式>>>提示符的问题

问题原因

这是因为VS Code默认的Python运行配置可能启动了交互式解释器,或者运行时强制进入了交互模式,导致脚本执行完后停留在>>>提示符,无法直接执行系统命令。

解决方法

1. 修改launch.json运行配置

  • 打开VS Code,按下Ctrl+Shift+D(或点击左侧运行图标)进入运行面板
  • 点击「创建launch.json文件」,选择Python环境
  • 在生成的launch.json中,调整以下配置项:
    • 将"console"设为"integratedTerminal"(或"externalTerminal")
    • 添加"stopOnEntry": false(禁止运行时自动进入调试交互模式)
    • 确保"justMyCode": true
      示例配置片段:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: 当前文件",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "stopOnEntry": false,
                "justMyCode": true
            }
        ]
    }
    

2. 使用正确的运行快捷键

  • 直接用Ctrl+F5(不调试运行)执行当前Python文件,脚本跑完后会自动回到系统shell提示符
  • 或者右键编辑器空白处,选择「在终端中运行Python文件」,避免触发交互式模式

3. 检查VS Code设置

  • 打开设置(Ctrl+,),搜索Python › Terminal: Launch Args,确保没有添加-i参数(这个参数会强制启动交互式解释器)
  • 勾选Python › Terminal: Execute In File Dir,让终端在脚本所在目录启动,避免路径问题

用户终端输出示例:

/usr/bin/python3
wwti@I-Air ~ % /usr/bin/python3
Python 3.9.6 (default, Oct 18 2022, 12:41:40) 
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hi")
Hi
>>> 

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 21:15:35