用VsCode调试python模块
我试图调试一个以模块为参数的python程序(请参见用VsCode调试python模块,python,visual-studio-code,Python,Visual Studio Code,我试图调试一个以模块为参数的python程序(请参见args)。launch.json配置如下: { "name": "Python: Actions", "type": "python", "request": "launch", "module": "my_module", "args": [ "--module", "module" ],
args
)。launch.json
配置如下:
{
"name": "Python: Actions",
"type": "python",
"request": "launch",
"module": "my_module",
"args": [
"--module",
"module"
],
"cwd": "/cwd",
"console": "integratedTerminal"
},
当我像这样运行程序时,它会工作:
python-m my_模块——模块
但是,当我启动调试配置时,它找不到作为参数传递的模块。以下是启动de config时vscode发出的命令行语句:
cd /cwd ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /path/to/python ~/.vscode/extensions/ms-python.python-2018.12.1/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 60664 -m my_module --module module
目前,VSCode的CLI解析器需要一些帮助,以避免将其参数与模块的参数混淆:
{
"name": "debugging-my-module",
"type": "python",
"request": "launch",
"module": "my_module",
"args": [
"--"
"optional",
"args",
"for",
"your",
"module",
],
"console": "integratedTerminal"
},
删除cwd并将路径添加到脚本中?您是否建议删除cwd
选项?不,可以。添加一个额外的“-”参数,这就是这里的诀窍所在。