You can run your program into pdb from the command line by running

python -m pdb your_script.py

It will break on the 1st line, then you'll be able to add a breakpoint wherever you want in your code using the break command, its syntax is:

b(reak) [[filename:]lineno | function[, condition]]

It is flexible enough to give you the ability to add a breakpoint anywhere.

Answer from mdeous on Stack Overflow
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί pdb.html
pdb β€” The Python Debugger
It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame.
Discussions

pdb trace don't stop where I put the breakpoint
Maybe something goes wrong with the import being in the middle of a decorated function... Try removing the decoration, and moving the import pdb to the top of the file. More on reddit.com
🌐 r/learnpython
5
0
June 1, 2023
(python dev) Guys, what do you use to examine values/ debug when running scripts?
Hey, also a python dev. I mainly do two things: - `M-x pdb` which allows emacs to debug via pdb. Pops up a pdb shell buffer and on the source file, there is an indicator of which line its in (I think its called "fringe"?) - Use `vterm` (shell) to fire up `pudb`, a 3rd party debugger that I greatly enjoy using. By using those two methods, I've gotten pretty far. I primarily use the 2nd option since the `pudb` UI is more fleshed out than the bare bones `pdb ` support emacs has. (Still its good enough). Note: I don't use LSP/eglot, but I have heard great things from DAP/Dape. Hope that helps, take care More on reddit.com
🌐 r/emacs
26
5
June 30, 2023
how do I debug a python script?
In emacs you can run `M-x pdb` which will run `pdb` debugger. Assuming you have a simple script called homework1.py , you can do M-x pdb in the prompt that follows enter "python -m pdb homework1.py " Emacs will pop a pdb shell in another window and you can run commands. There will also be a little arrow on the sides of the source code window showing you which number line you are in. Honestly, I would recommend simply doing the debugging via a terminal since you are rather new to emacs and you might be overloaded with unnecessary info at this point. More on reddit.com
🌐 r/emacs
8
0
January 12, 2024
Best way to debug python docker with docker compose? (Aside from vscode)
I am personally not an IDE person, so I use independent tools. Those work just as well inside Docker as outside. Often that's pdb, specifically pdb.set_trace(); that opens a python shell wherever in the code it is, and I can then mess around with things there. A useful thing to know is that you can get a shell on a running container via docker exec -it bash. More on reddit.com
🌐 r/learnpython
2
3
February 22, 2023
🌐
Real Python
realpython.com β€Ί python-debugging-pdb
Python Debugging With Pdb – Real Python
May 19, 2023 - Use the command b (break) to set a breakpoint. You can specify a line number or a function name where execution is stopped. ... If filename: is not specified before the line number lineno, then the current source file is used.
🌐
DigitalOcean
digitalocean.com β€Ί community β€Ί tutorials β€Ί python-breakpoint
Python breakpoint() | DigitalOcean
August 4, 2022 - Python breakpoint() is a new built-in function introduced in Python 3.7. Python code debugging has always been a painful process because of the tight coupling between the actual code and the debugging module code. For example, if you are using pdb debugger, then you will have to call ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί debugging-python-code-using-breakpoint-and-pdb
Debugging Python code using breakpoint() and pdb - GeeksforGeeks
July 11, 2025 - Let's see some basics of debugging using the built-in breakpoint() function and pdb module. We know that a debugger plays an important role when we want to find a bug in a particular line of code. Here, Python comes with the latest built-in function breakpoint() which does the same thing as pdb.set_trace() in Python 3.6 and below versions.
🌐
Dylanpaulus
dylanpaulus.com β€Ί posts β€Ί debugging-using-python
Faster and Easier Python Debugging with breakpoint() and PDB
May 8, 2023 - PDB is a module that provides an ... a running program. With PDB, we can set breakpoints, step through the code line by line, examine variables and expressions, modify values, and more....
🌐
Sunscrapers
sunscrapers.com β€Ί blog β€Ί python-debugging-guide-pdb
Debugging Python Apps: A Comprehensive Guide to pdb
September 8, 2023 - To explore Python debugging with pdb, this article introduces its features, commands, real-world applications, and third-party enhancements.
Find elsewhere
🌐
W3Resource
w3resource.com β€Ί python-interview β€Ί what-are-breakpoints-in-debugging-and-how-do-you-set-them-using-pdb-in-python.php
Using breakpoints for effective debugging with pdb in Python
Here's how you can set breakpoints at specific lines in the code using 'pdb': ... First, import the "pdb" module at the beginning of your Python script to use the "pdb" debugger.
🌐
Python Module of the Week
pymotw.com β€Ί 2 β€Ί pdb
pdb – Interactive Debugger - Python Module of the Week
July 3, 2010 - Using a temporary breakpoint lets you reach a particular spot in the program flow quickly, just as with a regular breakpoint, but since it is cleared immediately it does not interfere with subsequent progress if that part of the program is run repeatedly. $ python -m pdb pdb_break.py > .../pdb_break.py(7)<module>() -> def calc(i, n): (Pdb) tbreak 11 Breakpoint 1 at .../pdb_break.py:11 (Pdb) continue i = 0 j = 0 i = 1 j = 5 Deleted breakpoint 1 > .../pdb_break.py(11)calc() -> print 'Positive!'
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-debugger-python-pdb
Python Debugger – Python pdb - GeeksforGeeks
November 4, 2022 - To start debugging within the program just insert import pdb, pdb.set_trace() commands. Run your script normally, and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace(). With python 3.7 and later versions, there is a built-in function called breakpoint() which works in the same manner.
🌐
Python
peps.python.org β€Ί pep-0553
PEP 553 – Built-in breakpoint() | peps.python.org
This PEP proposes adding a new built-in function called breakpoint() which enters a Python debugger at the point of the call. Additionally, two new names are added to the sys module to make the choice of which debugger is entered configurable.
🌐
Juha-Matti Santala
hamatti.org β€Ί posts β€Ί debug-with-pdb-and-breakpoint
Debug with pdb and breakpoint : Juha-Matti Santala
August 9, 2024 - In this session, you can do what you would normally do in the REPL: you can run Python code, examine the state of variables, execute functions and so on: ... # args prints out all the arguments of the current function and their values (Pdb) args x = 3 # list shows the context: where are we in the code (Pdb) list 1 def double(x): 2 breakpoint() 3 -> return x * 2 4 5 6 val = 3 7 print(f"{val} * 2 is {double(val)}") # where shows us the current stack: how did we end up here (Pdb) where /code/testbench/breakpoints/example.py(7)<module>() -> print(f"{val} * 2 is {double(val)}") > /code/testbench/breakpoints/example.py(3)double() -> return x * 2 # step moves us forward (Pdb) step --Return-- > /code/testbench/breakpoints/example.py(3)double()->6 -> return x * 2 (Pdb) step 3 * 2 is 6 --Return-- > /code/testbench/breakpoints/example.py(7)<module>()->None -> print(f"{val} * 2 is {double(val)}")
🌐
Python Morsels
pythonmorsels.com β€Ί debugging-with-breakpoint
breakpoint: debugging in Python - Python Morsels
November 7, 2022 - Some of these other commands are occasionally useful, but you get a lot of debugging done with just a few PDB commands. Using print to debug your Python code does work, but it can sometimes be tedious. To start an interactive Python interpreter from right within your program, you can use the built-in breakpoint function to launch the Python debugger (a.k.a.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί pdb trace don't stop where i put the breakpoint
r/learnpython on Reddit: pdb trace don't stop where I put the breakpoint
June 1, 2023 -

Hi,

This is the problem, I have this:

@.mark.django_db
def test_it():
   .... # some code
a= ''
import pdb; pdb.set_trace()
b=''
   .... # some code

But It stops in:

> /usr/local/lib/python3.7/site-packages/pytz/__init__.py(230)utcoffset()
-> def utcoffset(self, dt):
(Pdb) l
225 def fromutc(self, dt):
226 if dt.tzinfo is None:
227 return self.localize(dt)
228 return super(utc.__class__, self).fromutc(dt)
229
230 -> def utcoffset(self, dt):
231 return ZERO
232
233 def tzname(self, dt):

And I don't know why. Any idea?

🌐
Red Hat
redhat.com β€Ί sysadmin β€Ί python-debugger-pdb
How to use the Python debugger (pdb) | Enable Sysadmin
November 20, 2025 - For example, set up a breakpoint on line 32, just before you create the workers list, and then j (jump) to line 36 and print the value of workers: (pythondebugger) $ python3 -m pdb simple_diagram.py --workers 2 my_airflow4.png > /home/josevnz/tutorials/PythonDebugger//simple_diagram.py(2)<module>() -> """ (Pdb) b simple_diagram.py:32 Breakpoint 1 at /home/josevnz/tutorials/PythonDebugger//simple_diagram.py:32 (Pdb) c > /home/josevnz/tutorials/PythonDebugger//simple_diagram.py(32)generate_diagram() -> with Cluster("Celery workers"): (Pdb) j 36 > /home/josevnz/tutorials/PythonDebugger//simple_diagram.py(36)generate_diagram() -> airflow - workers (Pdb) workers *** NameError: name 'workers' is not defined Β·
🌐
GitHub
github.com β€Ί spiside β€Ί pdb-tutorial
GitHub - spiside/pdb-tutorial: A simple tutorial about effectively using pdb Β· GitHub
The debugger is included in python's standard library and we use it the same way we would with any python library. First, we have to import the pdb module and then call one of its methods to add a debugging breakpoint in the program.
Starred by 901 users
Forked by 107 users
Languages Β  Python
🌐
SourceForge
bashdb.sourceforge.net β€Ί pydb β€Ί pydb β€Ί lib β€Ί subsubsection-brkpts.html
1.2.4 Breakpoints (break, tbreak, clear, commands, delete, disable, condition, ignore)
With a lineno argument, set a break at that line number in the current file. With a function argument, set a break at the first executable statement within that function. The line number may be prefixed with a filename and a colon to specify a breakpoint in another file (probably one that hasn't ...
🌐
HackerOne
pullrequest.com β€Ί blog β€Ί introduction-to-the-python-debugger-pdb-
Introduction to the Python Debugger (pdb) | HackerOne
To use pdb, you first need to import it into your Python script. This can be done by simply adding import pdb at the beginning of your file. Once imported, you can set breakpoints in your code by calling pdb.set_trace().
🌐
Python Engineer
python-engineer.com β€Ί posts β€Ί python-debugger-and-breakpoint
How to use the Python Debugger using the breakpoint() - Python Engineer
September 17, 2020 - It's very simple to get started. You can insert a breakpoint with the breakpoint() function at any position in your code . This is new in Python 3.7, and is equivalent to the older import pdb; pdb.set_trace() command.