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

VS Code调试Python带参脚本遇SystemExit:2错误求助

调试Python代码时遇到SystemExit:2错误的求助

最近在学习使用分步调试模式调试Python代码,执行args = parser.parse_args()时遇到SystemExit:2错误。

相关代码

import time
import torch
import numpy as np
from train_eval import train, init_network
from importlib import import_module
import argparse
from tensorboardX import SummaryWriter


parser = argparse.ArgumentParser(description='Chinese Text Classification')
parser.add_argument('--model', type=str, required=True, help='choose a model: TextCNN, TextRNN, FastText, TextRCNN, TextRNN_Att, DPCNN, Transformer')
parser.add_argument('--embedding', default='pre_trained', type=str, help='random or pre_trained')
parser.add_argument('--word', default=False, type=bool, help='True for word, False for char')
args = parser.parse_args()

经排查错误是调试时未传入参数导致的,于是修改了VS Code的launch.json配置,但问题仍然存在。而通过命令行执行python run.py --model TextRNN时代码运行正常,因此怀疑是调试设置的问题,希望能得到解决建议。

当前launch.json配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python_textRNN",
            "type": "python",
            "python": "D:\\miniconda\\envs\\ML3.8\\python.exe",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "showOutput": "always",
            "justMyCode": "true",
            "args": ["--model","TextRNN"]
        }
    ]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 15:15:06