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

如何在VS Code的launch.json配置中为Python解释器传递-u这类参数?

在VS Code调试中配置Python解释器参数(如-u)

要实现调试时执行python -u file.py,解释器级别的参数(比如-u)不能放在"args"字段(该字段用于传递给脚本的参数),需要使用"pythonArgs"字段来配置:

具体配置示例

修改.vscode/launch.json文件,添加"pythonArgs"字段并填入解释器参数:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件(带-u参数)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "pythonArgs": ["-u"],
            "args": [] // 这里填写脚本的参数,比如["--foo", "bar"]
        }
    ]
}

字段说明

  • "program": "${file}":表示调试当前打开的Python文件,对应命令里的file.py
  • "pythonArgs": ["-u"]:传递给Python解释器的参数,对应命令里的-u
  • "args":传递给脚本本身的命令行参数,比如脚本需要接收--input data.txt,就填["--input", "data.txt"]

配置完成后,启动该调试配置,就会以python -u 当前文件.py的形式运行调试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 14:17:04