VSCode Python Debugger



我正在尝试调试一个简单的python文件。test.py文件只包含文本打印("hello"(。当我选择Run->开始调试我得到一个带有以下文本的模式对话框:

h.toLowerCase不是函数

当我打开配置时,我看到:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "simple"
}
]
}

以下是导航到"帮助"的结果->关于->复制

版本:1.51.0(用户设置(提交:fcac248b077b55bae4ba5bab613fd6e9156c2f0c日期:2020-11-05T18:18:23.642Z电子:9.3.3铬:83.0.4103.122Node.js:12.14.1 V8:8.3.110.13-电子.0操作系统:Windows_NT x6410.0.19042

如果我启动一个命令窗口,我可以键入python或pip,所以这些东西就在我的路径上。

Python --version generates
3.9.0

VS代码扩展显示我安装了以下扩展。

Python v22020.10.332292344适用于VSCode 0.2.3 的Python

如果我在python文件中单击鼠标右键,然后在控制台中单击运行python。它工作正常;你好"在控制台中。

{
"name": "Python",
"type": "python",
"pythonPath":"${config.python.pythonPath}", 
"request": "launch",
"stopOnEntry": true,
"console": "none",
"program": "${file}",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"env": {"name":"value"}
}

好的,想好了。这篇文章很有帮助。

https://code.visualstudio.com/docs/python/debugging

有一个叫console的可选键。可能的值:internalConsole、externalTerminal或默认的integratedTerminal。暂时将此密钥设置为externalTerminal。运行F5或Run->再次启动调试。您将收到一条错误消息,内容如下。

Traceback (most recent call last):
File "...AppDataLocalProgramsPythonPython39librunpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "...AppDataLocalProgramsPythonPython39librunpy.py", line 87, in _run_code
exec(code, run_globals)
File "....vscodeextensionsms-python.python-2020.10.332292344pythonFileslibpythondebugpy__main__.py", line 45, in <module>
cli.main()
File "....vscodeextensionsms-python.python-2020.10.332292344pythonFileslibpythondebugpy/..debugpyservercli.py", line 430, in main
run()
File "....vscodeextensionsms-python.python-2020.10.332292344pythonFileslibpythondebugpy/..debugpyservercli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "...AppDataLocalProgramsPythonPython39librunpy.py", line 267, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "...AppDataLocalProgramsPythonPython39librunpy.py", line 242, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "...python.vscodelaunch.json", line 2
// Use IntelliSense to learn about possible attributes.
^
SyntaxError: invalid syntax
Press any key to continue . . .

错误消息指出它被Intellisense注释卡住了。作为开发人员,评论通常是一件好事。但这显然是模板化launch.json文件中的一个问题。如果您删除注释并将控制台键设置为internalConsole,事情似乎可以正常进行。

{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "simple",
"console": "internalConsole"
}
]
}

最新更新