vscode@调试debug配置@调试工作目录的切换
利用vscode 调试代码
debug abstract
-
python语言为例
- Debugging configurations for Python apps in Visual Studio Code
解决调式运行时文件同目录下的文件资源无法读取的问题
- Debugging configurations for Python apps in Visual Studio Code
创建更改调试配置json文件:
vscode+python:
-
-
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 apy_codefolder containingapp.py, and adatafolder containingsalaries.csv. If you start the debugger onpy_code/app.py, then the relative paths to the data file vary depending on the value ofcwd:cwd Relative path to data file Omitted or ${workspaceFolder}data/salaries.csv${workspaceFolder}/py_code../data/salaries.csv${workspaceFolder}/datasalaries.csv -
![在这里插入图片描述]()
-
调试的时候进入库@包的源码
-
When omitted or set to
true(the default), restricts debugging to user-written code only. Set tofalseto 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库打开图片为例:
![在这里插入图片描述]()




浙公网安备 33010602011771号