素材巴巴 > 程序开发 >

VSCode Python DEBUG 调试

程序开发 2023-09-06 18:35:48

Python VSCode 调试

VSCode Debug

VScode Debug Space

  1. Single file debug -> 选择 Open a file (在没有选中py文件的时候)VSCode Debug Open a file
    py文件必须是单个的可以执行的,不需调用参数文件
    在选中任意一个py文件后,这个选项就会消失
    pyVSCode Debug Selected one py file

  2. 新建Debug的launch file
    CreateVSCodeLaunchFile
    点击后,出现提示
    VSCodeCreatLaunchJsonSelect
    选择 “Python 文件 调试打开的 Python 文件”
    就会生成一个 Launch.json 的文件 在 .vscode 的文件夹下
    VSCodePythonLaunchJson

查看选择需要的解释器
selectPyInterpreter
selectInterpreter
编辑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: 当前文件", //需要调试的 py文件要打开并选中//     "type": "python",//     "request": "launch",//     "program": "${file}",//     "console": "integratedTerminal",//     "justMyCode": true// }    {"name": "Python", // 需要调试的 py文件要打开并选中"type": "python","request": "launch","stopOnEntry": false, //是否进入程序就Stop, 报错false is not defined"python": "C:\Users\YLwork\APPData\Local\Programs\Python\Python38\python.exe", // 自己的Python环境解释器地址, 很重要,如果有多个Python interpreter 的话,需要设置好"program": "${file}","cwd": "${workspaceRoot}","console": "integratedTerminal","justMyCode": true, //只调试自己的Code"args": ["examples\benchmarks\LightGBM\workflow_config_lightgbm_Alpha158_l1.yaml"], //需要输入的参数"env": {},"envFile": "${workspaceRoot}/.env","redirectOutput": true}]
 }
 

断点 Breakpoint

直接点击文件左侧,激活断点
VScode breakpoint

Reference

VSCode中Python的Debug调试配置
记录VSCode调试python一个极傻的坑:显示launch.json中name ‘true‘ is not defined

Version

0.0.1 - 2022May6


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。