Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
911 views
in Technique[技术] by (71.8m points)

Debugging Python In VScode ( // Use IntelliSense to learn about possible attributes. ^ SyntaxError: invalid syntax )

I used debug tool on VScode ( ctrl + shift + D ) with customized launch.json, but I cannot run my program. help me to fix this. This is my trace back

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
 "__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
 exec(code, run_globals)
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
 cli.main()
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
 run()
File "/home/odroid/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
 runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "/usr/lib/python3.6/runpy.py", line 261, in run_path
 code, fname = _get_code_from_file(run_name, path_name)
File "/usr/lib/python3.6/runpy.py", line 236, in _get_code_from_file
 code = compile(f.read(), fname, 'exec')
File "/home/odroid/Documents/python/crawling-worker/.vscode/launch.json", line 2
 // Use IntelliSense to learn about possible attributes.
  ^
SyntaxError: invalid syntax

*** This is my launch.json file ***

{
    // 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",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

This is my screen

question from:https://stackoverflow.com/questions/65713605/debugging-python-in-vscode-use-intellisense-to-learn-about-possible-attribu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to open the Python file you are trying to run in VS Code first.

"program": "${file}"

Tells VS Code to run the current file, and the current file you had open in VS Code was launch.json.

Alternatively you can specify an absolute path to the Python file you are trying to run.

"program": "Full/Path/To/Script.py"

Or a path relative to the current folder you have open in VS Code.

"program": "${workspaceFolder}/Script.py"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...