5

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.

matthiash
  • 3,105
  • 3
  • 23
  • 34

1 Answers1

1

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, ...

Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179
  • 4
    This is certainly easier than importing set_trace() and calling it, but it doesn't solve my problem, I still end up in interactiveshell.py when I type next. – matthiash Jul 07 '20 at 05:53