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

问题描述 投票:0回答:3

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

我正在发布输出的快照。

如有任何提示,我们将不胜感激。谢谢

python jupyter-notebook stderr
3个回答
2
投票

如果问题与打印有关,您可以使用

contextlib
重定向流:

import contextlib
import os

devnull = open(os.devnull, 'w')
contextlib.redirect_stderr(devnull)

0
投票

我使用CSS来解决方法:

%%html
<style>
    div.output_stderr {
    display: none;
    }
</style>

0
投票

您可以创建/修改您的 jupyter

_config.yml
文件以包含:

execute:
    stderr-output: remove  # One of 'show', 'remove', 'remove-warn', 'warn', 'error', 'severe'

您可以运行

jupyter --config-dir
来找到正确的位置。 请参阅Jupyter 的配置参考

© www.soinside.com 2019 - 2024. All rights reserved.