Interactive debugging in IPython (Jupyter) notebook
Asked Answered
A

1

9

For debugging my python code, I use the ipdb library, and use the set_trace() command to place a break point. Once the code reaches there, I get an interactive shell with ipdb> prompt, that I can explore local variables with tab autocompletion.

In IPython (Jupyter) notebook, however, ipdb.set_trace() does not work. As suggested by this post: using ipdb to debug python code in one cell (jupyter or Ipython)

I use the following alternative for interactive debugging:

from IPython.core.debugger import Tracer
Tracer()() #this one triggers the debugger

This gives me the ipdb> prompt, but the tab autocomplete is not available. Is there anyway to enable auto-complete for interactive debugging using ipython notebook? This is extremely useful, specially when you have a lot of variables with long names.

Aronson answered 8/11, 2016 at 15:13 Comment(1)
No, unfortunately the way those input prompts work does not allow tab completion.Cartogram
B
1

In Python 3.7 you can use breakpoint() function

This function drops you into the debugger at the call site. Specifically, it calls sys.breakpointhook(), passing args and kws straight through. By default, sys.breakpointhook() calls pdb.set_trace() expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly import pdb or type as much code to enter the debugger. However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice.

Breathless answered 20/7, 2018 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.