using ipdb to debug python code in one cell (jupyter or Ipython)

后端 未结 4 947
野的像风
野的像风 2020-12-12 11:58

I\'m using jupyter (or Ipython) notebook with firefox, and want to debug some python code in the cell. I am using \'import ipdb; ipdb.set_trace()\' as kind of breakpoint, fo

4条回答
  •  醉梦人生
    2020-12-12 12:53

    My version of Jupyter is 5.0.0 and my corresponding ipython version is 6.1.0. I am using

    import IPython.core.debugger
    dbg = IPython.core.debugger.Pdb()
    dbg.set_trace()
    

    Tracer is listed as deprecated.

    Update:

    I tried using the method from another answer https://stackoverflow.com/a/43086430/8019692 below but got an error:

    MultipleInstanceError: Multiple incompatible subclass instances of TerminalIPythonApp are being created.

    I prefer my method to the %%debug magic since I can set breakpoints in functions defined in other cells and run the function in another cell. Jupyter/IPython drops into the debugger in my function where the breakpoint is set, and I can use the usual pdb commands. To each his own...

    @lugger1, the accepted answer is deprecated.

提交回复
热议问题