VS Code Python launch.json 配置将 cwd 设置为特定模块目录

问题描述 投票:0回答:1

搜索这个问题,我找不到我需要的信息。

我在 VS Code 中的目录结构:

ProjectXYZ
|
-module1

我的 launch.json:

{
    "name": "Main File: Python",
    "type": "python",
    "request": "launch",
    "module": "module1",
    "console": "integratedTerminal",
    "justMyCode": true,
    "args": ["--env", "DEV"]
}

无论我在 VS Code 中的哪个文件上,我都想调试

module1
。然后我希望将 cwd 设置为 ProjectXYZ/module1 用于其他目的。照原样,断点处的 cwd 是 ProjectXYZ。

如果我将

"cwd": "${fileDirname}"
添加到 launch.json,它会在打开模块之前设置 cwd,并且无法再找到我的模块。 “cwd”的可能值在这里.

我的设置是否可以纯粹在 launch.json 中进行,或者我是否必须在启动后立即设置 cwd(我也不想在生产代码中这样做,只有在 VS 代码中调试时才这样做)。

谢谢!

python json visual-studio-code vscode-debugger launch
1个回答
0
投票

可以将cwd设置为ProjectXYZ/module1的绝对路径。你已经找到了文档.

${fileDirname} - current 打开文件的文件夹路径

将 cwd 设置为您想要的文件夹.

© www.soinside.com 2019 - 2024. All rights reserved.