vscode debug python launch.json添加args不起作用

问题

为了带入参数调试python 程序,按照网上搜到的教程配置了lauch.json文件,文件中添加了"args": ["model" "0" "path"]

json 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args":[ "****", "0", "*****" ]
        }
    ]
}

但是点击debug按钮,并没有读取到launch文件中的args参数,python中打印len(sys.argv)依然等于1。

原因

参考:vscode-python 中的 issues

vscode-doc: Python debugging in VS Code

简单来说就是:

1、界面右上角的debug按钮是一个扩展插件,是独立的debug系统,不读launch.json文件。所以在launch.json中的任何配置都不生效

2、F5/Run>Start Debugging,这两个选项都可以很好地与launch.json设置配合使用。

解决方案

1、按F5(或菜单栏Run->Start Debugging)

2、在launch.json里添加"purpose": ["debug-in-terminal"], 使用purpose注意事项

3、点击左侧debug窗口里面的debug按钮,它与debug系统是集成的。

相关推荐
洛的地理研学14 小时前
gma 绘制唐都畿道一府四州
python·gma 教程
张3蜂14 小时前
Python变量与命名规范:从入门到精通
开发语言·python
秦始皇爱找茬14 小时前
Playwright Python Windows 下 headful Chromium 崩溃排查经验分享
python·ui自动化·playwright
十铭忘14 小时前
动作识别12——yolo26s-pose+PoseC3D第1篇之标注工具升级2.0
人工智能·python·深度学习
你怎么知道我是队长14 小时前
VsCode插件推荐---Todo Tree
ide·vscode·编辑器
才兄说14 小时前
机器人租售配合齐不齐?多人同步操作
python
becatjd15 小时前
VScode的claude code插件报错command ‘claude-vscode.editor.openLast‘ not found
ide·vscode·编辑器·claude·anthropic·claude code
好家伙VCC15 小时前
# 发散创新:基于Python的TTS语音合成实战与优化策略 在人工智能加速落地的今天,**文本转
java·开发语言·人工智能·python
yuankoudaodaokou15 小时前
如何让三维数字化技术落地?思看科技三级认证培训体系赋能用户成长
python·科技