costisst
costisst

Reputation: 391

How to block stderr output in Jupyter Notebook?

I am running a Python script in Jupyter Notebook and a library I am using (PyNN), produces a lot of stderr output that slows down the code and fills up the memory. I have tried using %%capture at the beginning of the cell but nothing has changed, and the output remains the same.

I am posting a snap of the output.enter image description here

Any tips are appreciated. Thanks

Upvotes: 5

Views: 4037

Answers (2)

felix f
felix f

Reputation: 1

I use css to workaround:

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

Upvotes: 0

Maximilian Burszley
Maximilian Burszley

Reputation: 19694

If the issue is with printing, you can redirect the stream with contextlib:

import contextlib
import os

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

Upvotes: 2

Related Questions