How to format IPython starck trace. (IPythonのスタックトレースを見やすくする)
Problem
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 theverbose 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.
https://stackoverflow.com/questions/1261668/cannot-override-sys-excepthook
Here is how to make it work, using one of those formatting tool TBVaccine (https://github.com/skorokithakis/tbvaccine).
I wrote following at the python initial code(script set for $PYTHONSTARTUP).
into this
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
Moreover, although there are several libraries which can format the stack traces, they don't work with IPython, because IPython skip standard sys.excepthook.
https://stackoverflow.com/questions/1261668/cannot-override-sys-excepthook
Here is how to make it work, using one of those formatting tool TBVaccine (https://github.com/skorokithakis/tbvaccine).
I wrote following at the python initial code(script set for $PYTHONSTARTUP).
try: import tbvaccine kargs = {"code_dir":os.getenv('PWD'), "isolate":True, "show_vars":False} tbvaccine.add_hook(**kargs) 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: passthis makes
into this
Comments