Hide all warnings in IPython


I need to produce a screencast of an IPython session, and to avoid confusing viewers, I want to disable all warnings emitted by warnings.warn calls from different packages. Is there a way to configure the ipythonrc file to automatically disable all such warnings?

Asked By: astrofrog




import warnings

inside ~/.ipython/profile_default/startup/disable-warnings.py.

Quite often it is useful to see a warning once. This can be set by:

Answered By: astrofrog

I hide the warnings in the pink boxes by running the following code in a cell:

from IPython.display import HTML
function code_toggle_err() {
 if (code_show_err){
 } else {
 code_show_err = !code_show_err
$( document ).ready(code_toggle_err);
To toggle on/off output_stderr, click <a href="javascript:code_toggle_err()">here</a>.''')
Answered By: matthiash

For JupyterLab, this should work (@Alasja):

from IPython.display import HTML

var code_show_err = false;
var code_toggle_err = function() {
    var stderrNodes = document.querySelectorAll('[data-mime-type="application/vnd.jupyter.stderr"]')
    var stderr = Array.from(stderrNodes)
    if (code_show_err){
        stderr.forEach(ele => ele.style.display = 'block');
    } else {
        stderr.forEach(ele => ele.style.display = 'none');
    code_show_err = !code_show_err
document.addEventListener('DOMContentLoaded', code_toggle_err);
To toggle on/off output_stderr, click <a onclick="javascript:code_toggle_err()">here</a>.''')
Answered By: ottowg

The accepted answer does not work in Jupyter (at least when using some libraries).

The JavaScript solutions here only hide warnings that are already showing but not warnings that would be shown in the future.

To hide/unhide warnings in Jupyter and JupyterLab I wrote the following script that essentially toggles CSS to hide/unhide warnings.

(function(on) {
    const e = $("<a>Setup failed</a>");
    const ns = "js_jupyter_suppress_warnings";
    var cssrules = $("#" + ns);
        cssrules = $("<style id='" + ns + "' type='text/css'>div.output_stderr { } </style>").appendTo("head");
    e.click(function() {
        var s = 'Showing';
        if(on) {
            s = 'Hiding';
            cssrules.append("div.output_stderr, div[data-mime-type*='.stderr'] { display:none; }");
        e.text(s + ' warnings (click to toggle)');
        on = !on;
Answered By: robert
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.