问题
I am trying to learn Python and set up VS Code's Python debugger as this video describes: https://www.lynda.com/Python-tutorials/Choosing-editor-IDE/661773/707220-4.html
However the instructor seems to be on VS Code 1.18 and I'm on 1.28. I set up the launch.json configuration up to how it appears in the video but I'm getting a green line under "debugOptions" that says "Property debugOptions is not allowed". Anyone know how I can set up my environment so that it works the way the instructor is explaining. I'm on Windows 10.
{
// 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",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"env":{},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOuput"
]
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost"
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "enter-your-module-name-here",
"console": "integratedTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "",
"console": "externalTerminal"
}
]
}
回答1:
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"env":{},
"envFile": "${workspaceRoot}/.env",
"console": "none" //add this and go
回答2:
Instead of
"debugOptions": [
"RedirectOutput"
],
use
"redirectOutput": true,
etc. Check for proper configuration options (and whether you want them) at VSCode debugging documentation. I can't seem to find the first two options at the first glance though, consider whether you need it and google it if so.
The whole first config block for you would then be
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"env":{},
"envFile": "${workspaceRoot}/.env",
"redirectOutput": true,
},
来源:https://stackoverflow.com/questions/52807693/vs-code-property-debug-options-not-allowed