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

相关推荐
梨子串桃子_5 小时前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
文言一心6 小时前
LINUX离线升级 Python 至 3.11.9 操作手册
linux·运维·python
诗词在线6 小时前
中国古代诗词名句按主题分类有哪些?(爱国 / 思乡 / 送别)
人工智能·python·分类·数据挖掘
高锰酸钾_6 小时前
机器学习-L1正则化和L2正则化解决过拟合问题
人工智能·python·机器学习
天天睡大觉7 小时前
Python学习11
网络·python·学习
智航GIS7 小时前
11.11 Pandas性能革命:向量化操作与内存优化实战指南
python·pandas
写代码的【黑咖啡】8 小时前
Python中的Selenium:强大的浏览器自动化工具
python·selenium·自动化
抠头专注python环境配置8 小时前
解决Windows安装PythonOCC报错:从“No module named ‘OCC’ ”到一键成功
人工智能·windows·python·3d·cad·pythonocc
华研前沿标杆游学8 小时前
2026年华研就业实践营|走进字节跳动,解锁科技行业职业新航向
python