Taming the verbosity of ipython tracebacks

John Ladasky john_ladasky at sbcglobal.net
Tue Feb 10 13:53:02 EST 2015


Hi folks,

I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.

Whenever I execute code from within ipython which triggers an exception -- any exception -- I get a page full of information.  The exceptions in my code trigger exceptions within ipython.

Every error message looks like this:

================================================================

ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-85f78e96b07a>", line 1, in <module>
  
<< MY ERRONEOUS CODE, AND THE EXCEPTION IT GENERATED, ARE PRINTED HERE >>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 1713, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'NameError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 759, in structured_traceback
    records = _fixed_getinnerframes(etb, context, tb_offset)
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 242, in _fixed_getinnerframes
    records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/usr/lib/python3.4/inspect.py", line 1332, in getinnerframes
    framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "/usr/lib/python3.4/inspect.py", line 1292, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/usr/lib/python3.4/inspect.py", line 583, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "/usr/lib/python3.4/inspect.py", line 629, in getmodule
    os.path.realpath(f)] = module.__name__
AttributeError: 'FakeModule' object has no attribute '__name__'

Unfortunately, your original traceback can not be constructed.

================================================================

When I run the same script directly from the Linux shell, I get a tidy traceback which tells me exactly what I want, and nothing more.  But then, obviously, I lose the interactive ipython shell's capabilities.

I would like to get rid of all that fluff surrounding my ipython error message.  I'm not sure what the purpose of the inspect module is, or what FakeModule is.  I wonder whether I have failed to install something correctly.  Any advice is appreciated!



More information about the Python-list mailing list