“Python:当前文件(集成终端)” - Visual Studio代码

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

我在调试python文件时打开VS代码集成终端时遇到问题。 VS代码说:'$ {file}无法解析。请打开一个编辑。'

我当时正在使用:https://www.youtube.com/watch?v=dNFgRUD2w68

我的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 (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": false
        }```
    ]
}
python terminal visual-studio-code
1个回答
1
投票

在Visual Studio Code中,您需要在运行和调试Python脚本之前打开工作区文件夹。如果没有,VSCode无法解析例如${file}${workspaceFolder}

打开工作区文件夹后,底部状态栏的颜色会发生变化(取决于您选择的主题),表明您现在位于工作区内。然后只需单击左侧栏上的调试符号和左上角的齿轮符号(您可以在其中单击以开始调试)。

这将在根目录(您的工作区)内自动创建一个.vscode文件夹,并在其中添加一个launch.json。现在${file}可以解决。

以下是VScode支持的predefined variables列表,它对配置调试选项非常有用。

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