Python Language Debugging Via IPython and ipdb


Example

If IPython (or Jupyter) are installed, the debugger can be invoked using:

import ipdb
ipdb.set_trace()

When reached, the code will exit and print:

 /home/usr/ook.py(3)<module>()
      1 import ipdb
      2 ipdb.set_trace()
----> 3 print("Hello world!")

ipdb>

Clearly, this means that one has to edit the code. There is a simpler way:

from IPython.core import ultratb
sys.excepthook = ultratb.FormattedTB(mode='Verbose',
                                     color_scheme='Linux',
                                     call_pdb=1)

This will cause the debugger to be called if there is an uncaught exception raised.