How to format IPython starck trace. (IPythonのスタックトレースを見やすくする)


IPython is absolutely great tool to create Python code interactively, but when I use complicated libraries like pandas or scipy, its stack trace gets very very long and it's hard to find where was the original mistake, thanks to the verbose rich texts explaining errors.

Moreover, although there are several libraries which can format the stack traces, they don't work with IPython, because IPython skip standard sys.excepthook.

Here is how to make it work, using one of those formatting tool TBVaccine (
I wrote following at the python initial code(script set for $PYTHONSTARTUP).
  import tbvaccine
  kargs = {"code_dir":os.getenv('PWD'), "isolate":True, "show_vars":False}

  if get_ipython(): # IPYTHON
    tbv = tbvaccine.TBVaccine(**kargs)
    def f(*args, **argv): tbv.print_exception(*sys.exc_info())
    get_ipython().showtraceback = f
except Exception as e:
this makes

into this


Popular posts from this blog

Subclassing and Signal connect on a same widget crashes PySide application on exit.

Calling OpenCV functions via Cython from Python 3.X.

Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)