【问题标题】:Debugging Python In VScode ( // Use IntelliSense to learn about possible attributes. ^ SyntaxError: invalid syntax )在 VScode 中调试 Python ( // 使用 IntelliSense 了解可能的属性。^ SyntaxError: invalid syntax )
【发布时间】:2021-04-19 03:43:13
【问题描述】:

我在 VScode ( ctrl + shift + D ) 上使用了带有自定义launch.json 的调试工具,但我无法运行我的程序。 帮我解决这个问题。 这是我的回溯

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

***这是我的launch.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",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

【问题讨论】:

  • 您是否尝试将 JSON 文件作为 Python 运行?

标签: python debugging visual-studio-code web-crawler remote-debugging


【解决方案1】:

您需要先打开您尝试在 VS Code 中运行的 Python 文件。

"program": "${file}"

告诉 VS Code 运行当前文件,而你在 VS Code 中打开的当前文件是 launch.json。

或者,您可以指定要尝试运行的 Python 文件的绝对路径。

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

或相对于您在 VS Code 中打开的当前文件夹的路径。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2021-07-27
    • 2014-09-29
    • 2015-06-10
    • 2022-07-02
    相关资源
    最近更新 更多