0

每次执行错误时,Jupyter Notebook 崩溃,但在笔记本上不显示错误,但在 Jupyter 提示符上显示。

它迫使我每次都重新启动笔记本并执行所有单元格。

Notebook 写入错误时卡顿的截图

[IPKernelApp] ERROR | Exception in message handler:

Traceback (most recent call last):
  File "/Users/<username>/.pyenv/versions/<venv-name>/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
   exec(code_obj, self.user_global_ns, self.user_ns)
  File "/var/folders/2n/9hgs5nvd6p35c_rzn95txrph00xv/T/ipykernel_7095/881478447.py", line 1, in <module>
   1+"letters"
TypeError: unsupported operand type(s) for +: 'int' and 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/<username>/.pyenv/versions/<venv-name>/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 1934, in showtraceback
   stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'
4

1 回答 1

0

修补程序

这并不能解决问题,但它为问题提供了临时解决方案。它允许在不使笔记本崩溃的情况下显示错误/执行错误

import traceback
try:
   1+"letters"
except:
   traceback.print_exc()
于 2022-01-24T17:13:51.857 回答