【问题标题】:"Python: Current File (Integrated Terminal)" - Visual Studio Code“Python:当前文件(集成终端)”——Visual Studio 代码
【发布时间】:2019-04-17 13:05:30
【问题描述】:

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

我正在与:https://www.youtube.com/watch?v=dNFgRUD2w68

我的启动.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
        }```
    ]
}

【问题讨论】:

  • 欢迎来到 Stack Overflow。您是否打开了工作区文件夹?
  • 我只打开了launch.json和settings.json...我必须打开一个工作区文件夹吗?
  • 这只是这个launch.json的一部分,但我只对这个Python有问题:当前文件(集成终端)。

标签: python terminal visual-studio-code


【解决方案1】:

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

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

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

这里是 VScode 支持的predefined variables 列表,它们对于配置调试选项非常有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多