跳过主要内容

Python 调试器

使用 python 调试器

  • 插入到您的任意 python 脚本中:
pip install --upgrade debugpy
import debugpy

# 允许其它计算机在指定IP地址及端口附加 debugpy
debugpy.listen(('localhost', 5678))

# 暂停程序直到一个远程调试器已附加
debugpy.wait_for_client()
  • 将如下配置添加到您的 IDE 调试器:
{
// 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 Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
}
]
}
  • 数据流启动后,点击调试器的开始按钮!

结果

这样就可以使用实时调试器调试 python 代码