pan*_*ark 2 python visual-studio-code jupyter-notebook
我的问题是,当我在 while 循环中放置断点时,在 VSCode 中调试 jupyter 笔记本无法正常工作。
这是一个工作示例:
i = 1
while i < 5:
i+=1
Run Code Online (Sandbox Code Playgroud)
当此代码位于 python 文件中时,在最后一行放置断点有效,但当此代码位于 jupyter 笔记本单元中时则无效。更准确地说,我可以放置一个断点,但是调试时,它不会停在断点处。终端也出现错误(我用 替换了我的真实姓名myname):
Traceback (most recent call last):
File "/home/myname/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/myname/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/myname/.vscode/extensions/ms-python.python-2022.2.1924087327/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/myname/.vscode/extensions/ms-python.python-2022.2.1924087327/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
run()
File "/home/myname/.vscode/extensions/ms-python.python-2022.2.1924087327/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 "/home/myname/anaconda3/lib/python3.9/runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "/home/myname/anaconda3/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/home/myname/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/myname/Documents/myname/experiments/jupyter-nb/como_logger_test.ipynb", line 72, in <module>
"scrolled": true
NameError: name 'true' is not defined
(base) myname@Mallow:~/Documents/myname/experiments/jupyter-nb$ cd /home/myname/Documents/myname/experiments/jupyter-nb ; /usr/bin/env /home/myname/anaconda3/bin/python /home/myname/.vscode/extensions/ms-python.python-2022.2.1924087327/pythonFiles/lib/python/debugpy/launcher 37663 -- /home/myname/Documents/myname/experiments/jupyter-nb/test.ipynb
Run Code Online (Sandbox Code Playgroud)
我在谷歌搜索时没有找到与此问题相关的任何内容vscode debugging "while loop" jupyter notebook error。
编辑:问题特定于 while 循环。将 while 循环替换为 for 循环时:
for i in range(5):
print(i)
Run Code Online (Sandbox Code Playgroud)
调试行为符合预期。
调试 Jupyter Notebook:
调试 Jupyter Notebook 有两种不同的方法:一种称为“按行运行”的更简单模式,以及完全调试模式。
按行运行 通过 按行运行,您可以一次一行执行单元格,而不会被其他 VS Code 调试功能分散注意力。
调试单元 如果要使用 VS Code 中支持的全套调试功能(例如断点以及单步执行其他单元和模块的功能),则可以使用完整的 VS Code 调试器。
上述所有内容的文档都在这里: https ://code.visualstudio.com/docs/datascience/jupyter-notebooks
| 归档时间: |
|
| 查看次数: |
7198 次 |
| 最近记录: |