[PYTHON] [Jupyter Notebook / Lab] 3 ways to debug on Jupyter [Pdb]

I want to debug on Jupyter

I want to stop trying to find the root of debugging by inserting a print statement and executing it over and over again.

--How to specify a breakpoint and debug --How to start the debugger when an error occurs --Applies only to specific cells --Applies to the entire notebook

I will introduce three methods.

Debugging to specify breakpoints

If you know the line you want to debug, Insert the following line between the lines you want to debug.

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

Execution example

The following is an example of a break when ʻi becomes 10. You can certainly see ʻi = 10.

Debug when bugs occur

If you want to start Pdb when a bug occurs somewhere.

** If you want to apply only to a specific cell **, put the following row at the beginning of the cell.


%%debug

** If you want to apply it to the entire notebook **, put the following line somewhere.

%pdb on
# %pdb off ← When you want to turn off debug detection mode

Execution example

I'm intentionally raising an error when ʻi == 10`. The debugger is running properly.

Frequently used commands

Python Ipdb Cheatsheet

Isn't it here? Please let me know if it is convenient.

command Description
w Show stack trace(where)
n Run until next line(next)
c Continue execution until next breakpoint(continue)
q Run to the end and finish(quit)
d Dive into a function(down)
u Get out of the function(up)
s Execute until the next function call(step)
r Run until the current function returns(return)

Recommended Posts

[Jupyter Notebook / Lab] 3 ways to debug on Jupyter [Pdb]
How to debug with Jupyter or iPython Notebook
How to view progress bar on Jupyter Notebook to see progress
Introduced Jupyter Notebook to CentOS 7
High charts on Jupyter notebook
View PDF on Jupyter Notebook
Label images on jupyter lab
Run Jupyter Notebook on windows
How to use Jupyter Notebook
Steps to attach and debug from VS Code to Jupyter Lab on a remote server
Unable to display tensorboard in jupyter notebook on docker (solved)
A very convenient way to give a presentation on Jupyter Notebook
Formatting with autopep8 on Jupyter notebook
Run azure ML on jupyter notebook
Easy to use Jupyter notebook (Python3.5)
Try running Jupyter Notebook on Mac
Day 65 I installed matplotlib to draw graphs on my Jupyter notebook.
A simple way to launch Jupyter Notebook / Lab and set a password
I tried to visualize BigQuery data using Jupyter Lab on GCP
Install Anaconda on Mac and upload Jupyter (IPython) notebook to Anaconda Cloud
Memory leak in Python Jupyter Lab (Notebook)?
Markdown to get Jupyter notebook results to Qiita
I want to blog with Jupyter Notebook
Use Jupyter Lab and Jupyter Notebook with EC2
Make Jupyter Notebook a service on CentOS
Try SVM with scikit-learn on Jupyter Notebook
Start jupyter notebook on GPU server (remote server)
I want to display an image on Jupyter Notebook using OpenCV (mac)
How to execute commands in jupyter notebook
How to set up a jupyter notebook on ssh destination (AWS EC2)
Clone the github repository on jupyter notebook
How to use jupyter notebook with ABCI
GPU check of PC on jupyter notebook
Display histogram / scatter plot on Jupyter Notebook
Build jupyter notebook on remote server (CentOS)
Let's make jupyter lab easy to use
Jupyter Notebook Basics of how to use
Use vim keybindings on Docker-launched Jupyter Notebook
Run Jupyter notebook on a remote server
How to use Jupyter notebook [Super Basic]
How to install Fast.ai on Alibaba Cloud GPU and run it on Jupyter notebook
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Library for "I want to do that" of data science on Jupyter Notebook
Install matplotlib and display graph on Jupyter Notebook
Various ways to execute .py files on Windows
How to make multiple kernels selectable on Jupyter
Enable Jupyter Notebook with conda on remote server
[Pythonocc] I tried using CAD on jupyter notebook
Simply display a line graph on Jupyter Notebook
How to Git from GCP's Jupyter Lab to GSR
Jupyter Notebook Settings-How to use (EC2 Amazon Linux 2)
Try Apache Spark on Jupyter Notebook (on local Docker
Remotely open Jupyter notebook launched on the server
jupyter notebook does not start on mac fish
Jupyter Notebook memo
Introducing Jupyter Notebook
Jupyter Lab begins
Powerful Jupyter Notebook
Golang on jupyter
Jupyter on AWS
Jupyter notebook password