如何使用python调试VSCode上的GoogleCodeJam交互问题?

如何使用python调试VSCode上的GoogleCodeJam交互问题?,python,python-3.x,debugging,visual-studio-code,Python,Python 3.x,Debugging,Visual Studio Code,我试着下载示例交互问题。它们在Description选项卡中提供了一个本地测试工具,在Analysis选项卡中提供了一个python解决方案,可以同时运行两个脚本 在将解决方案保存到solution.py中后,我可以在shell上使用:python3 interactive\u runner.py python3 local\u testing\u tool.py 0--python3 solution.py成功地运行它 问题是我无法使用VSCode调试它。我尝试将所有3个文件放在一个文件夹中,

我试着下载示例交互问题。它们在Description选项卡中提供了一个
本地测试工具
,在Analysis选项卡中提供了一个python解决方案,可以同时运行两个脚本

在将解决方案保存到
solution.py
中后,我可以在shell上使用:
python3 interactive\u runner.py python3 local\u testing\u tool.py 0--python3 solution.py
成功地运行它

问题是我无法使用VSCode调试它。我尝试将所有3个文件放在一个文件夹中,并使用以下launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Arquivo Atual",
            "type": "python",
            "request": "launch",
            "program": "interactive_runner.py python3 local_testing_tool.py 0 -- python3 ${file}",
            "console": "integratedTerminal",
        }
    ]
}
使用调试器运行solutions.py时,会出现以下错误:

env DEBUGPY_LAUNCHER_PORT=40453 /home/user/.pyenv/versions/3.8.2/bin/python3.8 /home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher "interactive_runner.py python3 local_testing_tool.py 0 -- python3 /home/user/workspace/wargames/GoogleCodeJam/2018/PracticeSession/NumberGuessing/solution.py" 
Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/../debugpy/server/cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 262, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 232, in _get_code_from_file
    with io.open_code(fname) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'interactive_runner.py python3 local_testing_tool.py 0 -- python3 /home/user/workspace/wargames/GoogleCodeJam/2018/PracticeSession/NumberGuessing/solution.py'
env-DEBUGPY_-LAUNCHER_-PORT=40453/home/user/.pyenv/versions/3.8.2/bin/python3.8/home/user/.vscode/extensions/ms-python.python-2020.4.74986/pythonFiles/lib/python/DEBUGPY/no_-wheels/DEBUGPY/LAUNCHER“interactive_runner.py python3 local_testing_tool.py 0——python3/home/user/workspace/wargames/GoogleCodeJam/2018/Practicessession/NumberGuessing/solution.py”
回溯(最近一次呼叫最后一次):
文件“/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py”,第193行,位于主运行模块中
返回运行代码(代码、主全局、无、,
文件“/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py”,第86行,在运行代码中
exec(代码、运行\全局)
文件“/home/user/.vscode/extensions/ms python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_wheels/debugpy/______.py”,第45行
cli.main()
文件“/home/user/.vscode/extensions/ms python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_-wheels/debugpy/。/debugpy/server/cli.py”,第430行,主文件
运行()
文件“/home/user/.vscode/extensions/ms python.python-2020.4.74986/pythonFiles/lib/python/debugpy/no_-wheels/debugpy/。/debugpy/server/cli.py”,第267行,在run_文件中
runpy.run\u路径(options.target,run\u name=compat.force\u str(“\uuuuu main\uuuu”))
文件“/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py”,第262行,位于运行路径中
代码,fname=\u从\u文件(运行\u名称,路径\u名称)获取\u代码\u
文件“/home/user/.pyenv/versions/3.8.2/lib/python3.8/runpy.py”,第232行,从文件中获取代码
io.open_代码(fname)为f时:
FileNotFoundError:[Errno 2]没有这样的文件或目录:“interactive_runner.py python3 local_testing_tool.py 0--python3/home/user/workspace/wargames/GoogleCodeJam/2018/practicessession/NumberGuessing/solution.py”
有更好的方法吗?

参数“program”只需要文件的路径,因此会出现“没有这样的文件或目录”的错误。您要做的是将执行行的其余部分作为参数:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Arquivo Atual",
            "type": "python",
            "request": "launch",
            "program": "interactive_runner.py",
            "console": "integratedTerminal",
            "args": ["python3", "local_testing_tool.py", "0", "--", "python3", "${file}"]  // Not sure if `${file}` will work here.
        }
    ]
}

为什么需要指定两次python3?如果
interactive\u runner.py
正在为您运行Python,则可能会阻止调试器工作。@BrettCannon
interactive\u runner.py
运行两个程序(在本例中为Python):
python3 local\u testing\u tool.py 0
python3 solution.py
。它将一个程序的输出作为输入传递给另一个程序。这就是为什么有两个
python3
,实际上它们是3。