As I know, %debug magic
can do debug within one cell.
However, I have function calls across multiple cells.
For example,
In[1]:
A native debugger is being made available as an extension to JupyterLab. Released a few weeks ago, this can be installed by getting the relevant extension, as well as xeus-python kernel (which notably comes without the magics well-known to ipykernel users):
jupyter labextension install @jupyterlab/debugger
conda install xeus-python -c conda-forge
This enables a visual debugging experience well-known from other IDEs.
Source: A visual debugger for Jupyter
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.
Just type import pdb
in jupyter notebook, and then use this cheatsheet to debug. It's very convenient.
c
--> continue, s
--> step, b 12
--> set break point at line 12 and so on.
Some useful links: Python Official Document on pdb, Python pdb debugger examples for better understanding how to use the debugger commands.
Some useful screenshots:
The %pdb magic command is good to use as well. Just say %pdb on
and subsequently the pdb
debugger will run on all exceptions, no matter how deep in the call stack. Very handy.
If you have a particular line that you want to debug, just raise an exception there (often you already are!) or use the %debug
magic command that other folks have been suggesting.