What is the right way to debug in iPython notebook?

前端 未结 10 1631
不知归路
不知归路 2020-11-30 16:50

As I know, %debug magic can do debug within one cell.

However, I have function calls across multiple cells.

For example,

In[1]:          


        
相关标签:
10条回答
  • 2020-11-30 17:45

    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

    0 讨论(0)
  • 2020-11-30 17:48

    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.

    0 讨论(0)
  • 2020-11-30 17:49

    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:

    0 讨论(0)
  • 2020-11-30 17:49

    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.

    0 讨论(0)
提交回复
热议问题