Debugging Jupyter notebook: stepping through a cell

Viewed 3672

In a blank Jupyter notebook I enter the following code in a cell:

from IPython.core.debugger import set_trace
set_trace()
print("hello")

After running the cell, I get into debug mode (first screenshot). I want to step to the next line, so I use the command n(ext), as I do in pdb. But then I don't step to the print command, as I expected, but to some internal IPython code (second screenshot). How can I go to the next line in the cell code?

enter image description here

EDIT: As suggested by one answer, I substitute set_trace() with breakpoint(), but the result is still the same.

1 Answers

Python 3.7 includes built-in breakpoint() function. All you need to do enter:

breakpoint()

wherever you would like runtime to stop. You can use the same commands from pdb to move next, continue, run, ...

Related