What is the right way to debug in iPython notebook? What is the right way to debug in iPython notebook? python python

What is the right way to debug in iPython notebook?


You can use ipdb inside jupyter with:

from IPython.core.debugger import Tracer; Tracer()()

Edit: the functions above are deprecated since IPython 5.1. This is the new approach:

from IPython.core.debugger import set_trace

Add set_trace() where you need a breakpoint. Type help for ipdb commands when the input field appears.


Use ipdb

Install it via

pip install ipdb

Usage:

In[1]: def fun1(a):   def fun2(a):       import ipdb; ipdb.set_trace() # debugging starts here       return do_some_thing_about(b)   return fun2(a)In[2]: fun1(1)

For executing line by line use n and for step into a function use s and to exit from debugging prompt use c.

For complete list of available commands: https://appletree.or.kr/quick_reference_cards/Python/Python%20Debugger%20Cheatsheet.pdf


In Python 3.7 you can use breakpoint() function. Just enter

breakpoint()

wherever you would like runtime to stop and from there you can use the same pdb commands (r, c, n, ...) or evaluate your variables.