我遇到了一个关于在VSCode调试中使用参数的问题。

huangapple go评论81阅读模式
英文:

I met a question with of vscode debugging with arguments

问题

I found it's caused by running with no arguments, so I edited the launch.json file as referred to in this Stack Overflow post.

But I still encounter the error.

My code runs normally when using the command line like this: python run.py --model TextRNN. So, I think it's caused by my debug settings, but I don't know how to fix it. Could you please help me?

My settings

{
	"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"],
		},
	]
}
英文:

recently i am started to learn python with debugging mode step by step, but i am stuck in args = parser.parse_args()
with error: 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()

i found it's caused running with no arg, so i edit the launch.json refrerred https://stackoverflow.com/questions/51244223/visual-studio-code-how-debug-python-script-with-arguments

but still error

and my code run normally when using command line like python run.py --model TextRNN
so i think it's caused by my debug settings, but i don't know how to fix it , could you please help me?

My settings

{
	"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"],

		},
	]
}

答案1

得分: 1

你可能正在使用错误的调试方法。如果你已配置了 launch.json 并希望它能够正常工作,你需要使用 运行和调试 面板中的绿色三角形按钮来启动调试。

或者使用 运行 --> 启动调试/运行而不调试

但如果你直接在代码编辑页面右上角的三角形菜单下使用 调试 Python 文件,这将不会引用 launch.json 中的配置。

英文:

You may be using the wrong debugging method. If you configured launch.json and want it to work, you need to use the green triangle button in the Run and Debug panel to start debugging.

我遇到了一个关于在VSCode调试中使用参数的问题。

Or use Run --> Start Debugging/Run Without Debugging,

我遇到了一个关于在VSCode调试中使用参数的问题。

But if you directly use Debug Python File under the triangle menu in the upper right corner of the code editing page, this will not refer to the configuration in launch.json.

我遇到了一个关于在VSCode调试中使用参数的问题。

huangapple
  • 本文由 发表于 2023年6月19日 18:21:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505694.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定