【问题标题】:vs code not launching, config issue with launcher?vs 代码未启动,启动器的配置问题?
【发布时间】:2017-01-24 20:49:30
【问题描述】:

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

这里是“问题区域”的特写:

"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"
    }
]

【问题讨论】:

    标签: python json visual-studio-code launch


    【解决方案1】:

    这就是我所做的。它给了我同样的错误,但在它上面的代码上我看到了 (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"
            ]
        },
    

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

    【讨论】:

      【解决方案2】:

      错误表明缺少“程序”属性。如果我们查看该配置,

      {                        <----- 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": "${file}" 调试打开的文件。 "program": "${workspaceFolder}/foo.py" 调试工作区文件夹中的 foo.py。

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

      【讨论】:

      • 我在这里没有看到完整的答案。您已经准确地找到了错误的原因,但没有找到解决方案。当需要运行模块时,您能指出“程序”的价值吗?
      • 这不是一个完整的答案。
      • 'program'属性的正确值取决于你要调试什么,所以我不能告诉你如何修复它,但我添加了一些典型的例子。
      猜你喜欢
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 2020-06-05
      • 2020-11-11
      • 1970-01-01
      • 2022-08-07
      • 2022-01-12
      • 1970-01-01
      相关资源
      最近更新 更多