如何在 Jupyter Notebook 中阻止 stderr 输出?

cos*_*sst 5 python stderr jupyter-notebook

我正在 Jupyter Notebook 和我正在使用的库 (PyNN) 中运行 Python 脚本,会产生大量 stderr 输出,从而减慢代码速度并填满内存。我尝试在单元格的开头使用 %%capture 但没有任何改变,并且输出保持不变。

我正在发布输出的快照。在此输入图像描述

任何提示表示赞赏。谢谢

The*_*le1 2

如果问题与打印有关,您可以使用以下命令重定向流contextlib

import contextlib
import os

devnull = open(os.devnull, 'w')
contextlib.redirect_stderr(devnull)
Run Code Online (Sandbox Code Playgroud)