vscode@调试debug配置@调试工作目录的切换

利用vscode 调试代码

debug abstract

创建更改调试配置json文件:

vscode+python:

  • cwd

    • Specifies the current working directory for the debugger, which is the base folder for any relative paths used in code. If omitted, defaults to ${workspaceFolder} (the folder open in VS Code).

      As an example, say ${workspaceFolder} contains a py_code folder containing app.py, and a data folder containing salaries.csv. If you start the debugger on py_code/app.py, then the relative paths to the data file vary depending on the value of cwd:

      cwdRelative path to data file
      Omitted or ${workspaceFolder}data/salaries.csv
      ${workspaceFolder}/py_code../data/salaries.csv
      ${workspaceFolder}/datasalaries.csv
    • 在这里插入图片描述

调试的时候进入库@包的源码

  • justMyCode

    When omitted or set to true (the default), restricts debugging to user-written code only. Set to false to also enable debugging of standard library functions

  • 配置样例:

    • 项目根目录下:.vscode\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",
                  // 设置是否在调试的时候进入包/库的源码文件中
                  "justMyCode": false
              }
          ]
      }
      

code runner插件下的切换

  • ctrl+shift+p:

  • 输入settings进入配置:

    • 在这里插入图片描述
  • 将python的对应行修改为

    • "python": " cd $dir \n python $fileName",
  • 即可在运行时自动将目录切换到当前打开的文件所在目录,并顺利调用同目录的资源.

result:

  • 以PySide2库打开图片为例:
  • 在这里插入图片描述
posted @ 2021-05-30 18:33  xuchaoxin1375  阅读(33)  评论(0)    收藏  举报  来源