【发布时间】:2020-08-10 03:41:08
【问题描述】:
我尝试下载示例交互问题number guessing problem。他们在描述选项卡中提供local testing tool,在分析选项卡中提供python 解决方案,interactive_runner.py 同时运行两个脚本。
在 solution.py 中保存解决方案后,我可以在 shell 上成功运行它:python3 interactive_runner.py python3 local_testing_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'
有更好的方法吗?
【问题讨论】:
-
为什么要指定
python3两次?如果interactive_runner.py正在为您运行 Python,它可能会阻止调试器工作。 -
@BrettCannon
interactive_runner.py运行两个程序(在本例中为 python):python3 local_testing_tool.py 0和python3 solution.py。它将一个程序的输出作为输入传递给另一个程序。这就是为什么有两个python3,实际上它们是3。
标签: python python-3.x debugging visual-studio-code