如何在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
相关产品推荐
相关产品推荐

