Hide all warnings in ipython
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping
--
Chapters
00:00 Question
00:30 Accepted answer (Score 1165)
00:57 Answer 2 (Score 65)
01:19 Answer 3 (Score 13)
02:13 Answer 4 (Score 3)
02:41 Thank you
--
Full question
https://stackoverflow.com/questions/9031...
Answer 2 links:
[JupyterLab]: https://en.wikipedia.org/wiki/Project_Ju...
Answer 3 links:
[JupyterLab]: https://en.wikipedia.org/wiki/Project_Ju...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #warnings #ipython
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping
--
Chapters
00:00 Question
00:30 Accepted answer (Score 1165)
00:57 Answer 2 (Score 65)
01:19 Answer 3 (Score 13)
02:13 Answer 4 (Score 3)
02:41 Thank you
--
Full question
https://stackoverflow.com/questions/9031...
Answer 2 links:
[JupyterLab]: https://en.wikipedia.org/wiki/Project_Ju...
Answer 3 links:
[JupyterLab]: https://en.wikipedia.org/wiki/Project_Ju...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #warnings #ipython
#avk47
ACCEPTED ANSWER
Score 1251
Place:
import warnings
warnings.filterwarnings('ignore')
inside ~/.ipython/profile_default/startup/disable-warnings.py.
Quite often it is useful to see a warning once. This can be set by:
warnings.filterwarnings(action='once')
ANSWER 2
Score 65
I hide the warnings in the pink boxes by running the following code in a cell:
from IPython.display import HTML
HTML('''<script>
code_show_err=false;
function code_toggle_err() {
if (code_show_err){
$('div.output_stderr').hide();
} else {
$('div.output_stderr').show();
}
code_show_err = !code_show_err
}
$( document ).ready(code_toggle_err);
</script>
To toggle on/off output_stderr, click <a href="javascript:code_toggle_err()">here</a>.''')
ANSWER 3
Score 14
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.
%%javascript
(function(on) {
const e = $("<a>Setup failed</a>");
const ns = "js_jupyter_suppress_warnings";
var cssrules = $("#" + ns);
if(!cssrules.length)
cssrules = $("<style id='" + ns + "' type='text/css'>div.output_stderr { } </style>").appendTo("head");
e.click(function() {
var s = 'Showing';
cssrules.empty()
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;
}).click();
$(element).append(e);
})(true);
ANSWER 4
Score 5
For JupyterLab, this should work (@Alasja):
from IPython.display import HTML
HTML('''<script>
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);
</script>
To toggle on/off output_stderr, click <a onclick="javascript:code_toggle_err()">here</a>.''')