Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 632
astrofrog Avatar asked Jan 27 '12 10:01

astrofrog


People also ask

How do I stop deprecation warning in Python?

Answer #1: If you're on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int. (Note that in Python 3.2, deprecation warnings are ignored by default.)


2 Answers

I eventually figured it out. Place:

import warnings warnings.filterwarnings('ignore') 

inside ~/.ipython/profile_default/startup/disable-warnings.py. I'm leaving this question and answer for the record in case anyone else comes across the same issue.

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

warnings.filterwarnings(action='once') 
like image 67
astrofrog Avatar answered Oct 31 '22 17:10

astrofrog


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>.''') 
like image 28
matthiash Avatar answered Oct 31 '22 16:10

matthiash