Hi, I'm Chris

This blog is about programming, linux and other stuff.
Please don’t hesitate to contact me if you have any questions or suggestions for improvements!

Trigger ipdb within ipython notebook

This is gonna be a short one: If you want to trigger the ipdb and set breakpoints within the ipython notebook the following won’t work: import ipdb; ipdb.set_trace()

It will get you to the interactive debugger, but you won’t be able to do anything, e.g. print variables etc. (At least this was the case the last time I tried it).

Fortunately, you will get a working interactive debugger session by importing and calling the Tracer as described below (and also in this SO post):

from IPython.core.debugger import Tracer
def fobar(n):
    x = 1337
    y = x + n
    Tracer()() #this one triggers the debugger
    return y


As a quick reference for the debugger commands available I can warmly recommend the pdb cheatsheet by nblock.

comments powered by Disqus