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系统是集成的。

相关推荐
2401_889884663 分钟前
使用Pandas进行数据分析:从数据清洗到可视化
jvm·数据库·python
研究点啥好呢5 分钟前
3月15日GitHub热门项目推荐 | 从本地部署到生产实践
人工智能·python·github·cursor·vibe coding
no_work5 分钟前
卷积神经网络cnn图像识别项目合集
人工智能·python·深度学习·神经网络·机器学习·cnn
山川行6 分钟前
Git学习笔记:Git进阶操作
笔记·git·vscode·学习·编辑器·visual studio code
程序媛徐师姐10 分钟前
Python基于Django的网络漏洞扫描工具的开发与优化【附源码、文档说明】
python·django·漏洞扫描工具·漏洞扫描·网络漏洞扫描工具·python网络漏洞扫描工具·pytho网络漏洞扫描
zzb158011 分钟前
Agent学习-ReAct框架
java·人工智能·python·机器学习·ai
Dxy123931021613 分钟前
PyTorch的OneCycleLR详细介绍:解锁“超级收敛”的油门控制术
人工智能·pytorch·python
橘bird16 分钟前
LangChain1.2 学习笔记(自用)(未完结)
笔记·python·学习·langchain
四代机您发多少17 分钟前
从零开始训练一个大模型
人工智能·pytorch·python·transformer
秦牛正威18 分钟前
MacOS:Python `command not found` 问题修复记录
python