vs 代码未启动,启动器配置问题?

vs code not launching, config issue with launcher?

当我在 VS Code 中启动我的 .py 代码时,我收到配置错误 launch.json。查看 launch.json 的代码,它有一个警告“"Missing property "program” (40,9)“”。这是完整的代码,但我还包括了 vs 代码似乎有问题的区域的特写。

这是"problem area"的特写:

"debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {                        <----- this is the problem vs code is having
        "name": "Python Module",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",

这是完整的代码,如果您需要更全面地了解正在发生的事情:

"version": "0.2.0",
"configurations": [
    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "cwd": "${workspaceRoot}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {
        "name": "PySpark",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "osx": {
            "pythonPath": "${env.SPARK_HOME}/bin/spark-submit"
        },
        "windows": {
            "pythonPath": "${env.SPARK_HOME}/bin/spark-submit.cmd"
        },
        "linux": {
            "pythonPath": "${env.SPARK_HOME}/bin/spark-submit"
        },
        "program": "${file}",
        "cwd": "${workspaceRoot}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {                        <----- this is the problem vs code is having
        "name": "Python Module",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "module": "module.name",
        "cwd": "${workspaceRoot}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {
        "name": "Integrated Terminal/Console",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "cwd": "null",
        "console": "integratedTerminal",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit"
        ]
    },
    {
        "name": "External Terminal/Console",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "cwd": "null",
        "console": "externalTerminal",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit"
        ]
    },
    {
        "name": "Django",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${workspaceRoot}/manage.py",
        "cwd": "${workspaceRoot}",
        "args": [
            "runserver",
            "--noreload"
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput",
            "DjangoDebugging"
        ]
    },
    {
        "name": "Flask",
        "type": "python",
        "request": "launch",
        "stopOnEntry": false,
        "pythonPath": "${config.python.pythonPath}",
        "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter",
        "cwd": "${workspaceRoot}",
        "env": {
            "FLASK_APP": "${workspaceRoot}/quickstart/app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {
        "name": "Flask (old)",
        "type": "python",
        "request": "launch",
        "stopOnEntry": false,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${workspaceRoot}/run.py",
        "cwd": "${workspaceRoot}",
        "args": [],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {
        "name": "Watson",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${workspaceRoot}/console.py",
        "cwd": "${workspaceRoot}",
        "args": [
            "dev",
            "runserver",
            "--noreload=True"
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    {
        "name": "Attach (Remote Debug)",
        "type": "python",
        "request": "attach",
        "localRoot": "${workspaceRoot}",
        "remoteRoot": "${workspaceRoot}",
        "port": 3000,
        "secret": "my_secret",
        "host": "localhost"
    }
]

错误提示缺少 'program' 属性。如果我们查看该配置,

{                        <----- this is the problem vs code is having
    "name": "Python Module",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config.python.pythonPath}",
    "module": "module.name",
    "cwd": "${workspaceRoot}",
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "RedirectOutput"
    ]
},

果然没有'program'属性。它是必需的,所以如果你想使用那个配置,你应该添加它。

'program' 属性必须指向要开始调试的程序。示例:"program": "${file}" 调试打开的文件。 "program": "${workspaceFolder}/foo.py" 在您的工作区文件夹中调试 foo.py。

在文档中查看更多详细信息:https://github.com/DonJayamanne/pythonVSCode/wiki/Debugging

这是我所做的。它给了我同样的错误但是 (44,9) 在它上面的代码上我看到 "program": "${file}".

我在你的案例 (40) 中遇到问题的部分添加了该行,我将该代码放在 "cwd": "${workspaceRoot}/.env" 的正上方,所以我现在看起来像这样:

{
        "name": "Python Module",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config:python.pythonPath}",
        "module": "module.name",
        "program": "${file}",
        "cwd": "${workspaceRoot}",
        "env": {},
        "envFile": "${workspaceRoot}/.env",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },

这似乎解决了我的问题希望这对某人有帮助。