我在Windows 10 PC上使用VS Code,安装了Python 3.7.3和Python扩展。我按照这里的说明(https://code.visualstudio.com/docs/python/python-tutorial)在C:\python_work\hello中创建了一个名为'hello'的测试文件夹,并在该文件夹中创建了一个名为'hello.py'的程序。下面是hello.py的代码。我尝试通过点击绿色箭头和按下F5来使用调试器,但似乎都无法使调试器正常工作。我的'launch.json'文件也在下面显示。
hello.py:
msg = "Hello World!"
print(msg) # Breakpoint
launch.json:
{
// 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: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"stopOnEntry": true
},
]
}
我本来期望底部的状态栏变成橙色,并且程序在第二行停下来,让我可以在预览窗格中检查局部和全局变量。然而,底部的状态栏只保持橙色了半秒钟,程序继续运行,就好像我按下了“在终端中运行Python文件”,而没有在断点处停下来。请帮忙!
cd c:\python_work\hello && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\Python\python.exe c:\Users\RohanPC\.vscode\extensions\ms-python.python-2019.6.22090\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 49389 c:\python_work\hello\hello.py "
- rogo8888if __name__ == "__main__":
),并且在执行期间遇到Python异常,则VS Code会在主要部分中弹出消息框“Exception has occurred: System Exit”。此时,单击“运行->重新启动调试(shift-cmd-F5)”,然后就可以命中断点了。 - caucus