How to debug with Jupyter or iPython Notebook

It was a little talked about at a study session, so I looked it up.

Preparation

Just before the line you want to debug, add:

from IPython.core.debugger import Pdb; Pdb().set_trace()

You can use the Trace of ʻIPython.core.debugger`, but it is now treated as DEPRECATED. Reference: IPython issue # 9940

Run

If you execute it normally with Jupyter or iPython Notebook, the execution will be interrupted immediately after the line added in the previous section.

run1.png

Enter the command in the text field that appears after ʻipdb> . Help is displayed with h. It ends with q`.

ipdb command list

Reference: Python Ipdb Cheatsheet

Mobile system

command Description
n Run until next line(next)
c Continue execution until next breakpoint(continue)
unt line number Execute until the specified line is reached(until)
d Step in(down)
u Step out(up)
s Execute until the next function call(step)
r Run until the current function returns(return)
q Run to the end and finish(quit)

Display system

command Description
p variable name Show variable value(print)
a Show the arguments of the current function(args)
w Show stack trace(where)
h help(help)

Breakpoint setting system

command Description
b Line number or function name Set breakpoints(break)
tbreak line number or function name Set a temporary breakpoint(Deleted when a breakpoint is reached)
disable number Disable breakpoints
enable number Enable breakpoints
ignore number count Ignore breakpoints a specified number of times
condition number Condition to set Change the judgment value of the condition at the breakpoint
cl Remove all breakpoints(clear)

Recommended Posts

How to debug with Jupyter or iPython Notebook
How to use jupyter notebook with ABCI
[IPython] How to Share IPython Notebook
How to use IPython Notebook
Play with Jupyter Notebook (IPython Notebook)
How to use Jupyter Notebook
How to import NoteBook as a module in Jupyter (IPython)
How to import NoteBook as a module in Jupyter (IPython)
Use apache Spark with jupyter notebook (IPython notebook)
I want to blog with Jupyter Notebook
How to execute commands in jupyter notebook
Jupyter Notebook Basics of how to use
How to use Jupyter notebook [Super Basic]
Rich cell output with Jupyter Notebook (IPython)
How to revive cells in iPython notebook
How to batch start a python program created with Jupyter notebook
How to use jupyter notebook without polluting your environment with Docker
[Jupyter Notebook / Lab] 3 ways to debug on Jupyter [Pdb]
How to touch Jupyter Notebook without polluting the environment other than Pythonista, or how to touch Ruby with Jupyter Notebook without polluting the environment other than Rubyist
How to debug selenium
How to use IPython
Graph drawing with jupyter (ipython notebook) + matplotlib + vagrant
How to deal with "No module named'〇〇'" error in Jupyter Notebook | Install with! Pip!
How to process camera images with Teams or Zoom
EC2 provisioning with Vagrant + Jupyter (IPython Notebook) on Docker
How to instantly launch Jupyter Notebook from the terminal
How to (force) pdf conversion of IPython Notebook slides
How to view progress bar on Jupyter Notebook to see progress
Parallel computing with iPython notebook
Introduced Jupyter Notebook to CentOS 7
Using Graphviz with Jupyter Notebook
Use pip with Jupyter Notebook
How to change Jupyter layout
How to update with SQLAlchemy?
Use Cython with Jupyter Notebook
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
Run Apache-Spark with IPython Notebook
How to RDP with Fedora31
Graph drawing with IPython Notebook
How to Delete with SQLAlchemy?
Use Bokeh with IPython Notebook
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
I want to use a virtual environment with jupyter notebook!
How to see the contents of the Jupyter notebook ipynb file
The usual way to add a Kernel with Jupyter Notebook
Connect the Jupyter Notebook kernel to Spyder with Jupytext enabled
How to deal with the phenomenon that Python (Jupyter notebook) executed on WSL becomes Aborted
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS with anaconda
How to cancel RT with tweepy
Allow external connections with jupyter notebook
Formatting with autopep8 on Jupyter notebook
Python: How to use async with
Visualize decision trees with jupyter notebook
Make a sound with Jupyter notebook
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to deal with imbalanced data
How to get started with Scrapy