Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Python debugger pauses a program so you can inspect its current state, step through code, and find where behavior diverges from what you expect. For a quick terminal session, use Python’s built-in pdb; if your project is already open in an IDE, use the Python Debugger in VS Code or Debug mode in PyCharm. The core workflow is the same: set a breakpoint, start or attach the debugger, inspect values and the call stack, then step, continue, or stop.

What a Python debugger does

A debugger lets you examine a program while it is paused. Instead of relying only on print statements or reading a traceback after a failure, you can stop at a chosen line, inspect variables in the active stack frame, evaluate expressions, and follow execution one step at a time.

Most debugging sessions follow this sequence:

  1. Choose a stop point. Add a breakpoint in source code or configure one in an IDE.
  2. Start or attach. Launch the program under debugger control, or connect to a process that is already running when the tool and environment support it.
  3. Inspect. Check the current line, local values, expressions, and call stack.
  4. Move execution. Step into a function, step over a call, or continue to the next breakpoint.
  5. Finish. Resume normal execution or end the debugging session.

Choose a debugger for your situation

Situation Good starting point Why and what to check
Small script, terminal workflow, or quick investigation of an exception pdb It is included in Python’s standard library and supports stepping, inspection, stack navigation, and post-mortem debugging. See the Python 3.14.8 pdb reference.
Project already open in VS Code Python Debugger extension It offers a quick current-file command and configurable launch or attach sessions. See Microsoft’s VS Code Python debugging documentation.
Project already open in PyCharm PyCharm Debug mode It provides an IDE workflow for breakpoints and state inspection. Check the debugger mode and whether your interpreter and workflow are covered in the PyCharm debugger settings and PyCharm debugging guide.
Need to inspect an existing or remote process Compare each tool’s attach and remote-debugging path VS Code documents attach and remote workflows; PyCharm documents DAP attachment and notes scenarios outside debugpy coverage. Verify interpreter, framework, subprocess, and network-security requirements before choosing.

There is no universally best debugger. Compare whether you want a terminal or graphical interface, whether you can launch the program or need to attach, which Python interpreter and version are involved, and whether the target framework, remote host, WSL environment, or subprocesses are supported.

Use Python’s built-in pdb

pdb is Python’s interactive source debugger. In the default configuration, calling breakpoint() enters it at that point in the program. The following runnable example pauses before calculating a result:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
def calculate_total(prices):
    subtotal = sum(prices)
    breakpoint()
    return subtotal

print(calculate_total([12.50, 7.50]))

Save the code to a file such as debug_example.py, then run it normally with python debug_example.py. At the (Pdb) prompt, the program is paused on the breakpoint line. Enter one command at a time:

Command What it does
p expression Evaluates and prints an expression in the current frame, for example p subtotal.
where or w Shows the stack, including the current frame.
list Lists source around the current line.
step or s Runs the next line and enters a called function when execution reaches it.
next or n Runs the next line without stepping into a called function.
continue or c Resumes execution until another breakpoint or the program ends.
quit or q Ends the debugging session.

Launch a script under pdb

You do not need to insert breakpoint() to start a session. Run the script with:

python -m pdb path/to/script.py

This starts the script under debugger control. The pdb module also enters post-mortem debugging when a program exits abnormally, allowing you to examine the state around the exception. To inspect the last exception from an interactive session, Python documents pdb.pm().

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Conditional breakpoints and frame inspection

For a breakpoint that should trigger only when a condition is true, use the break command with a line and condition, for example b 42, count > 10. Use where to understand how execution reached the current frame, then use up or down to move through stack frames. Expressions evaluated with p use the selected frame’s context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python 3.14 process attachment

Python 3.14 adds the -p or --pid option for attaching pdb to a process by ID:

python -m pdb -p 12345

Replace 12345 with the target process ID. This option is specific to Python 3.14 and newer; do not assume it is available in earlier versions. The Python documentation cautions that a process blocked in a system call or waiting for I/O may not be attachable until it executes another bytecode instruction or receives a signal. Python 3.14 also documents a monitoring backend and async entry points; consult the versioned reference for details and compatibility.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Debug a Python file in VS Code

Start a quick session for the open file

  1. Open the project or Python file in VS Code and confirm the intended Python interpreter is selected.
  2. Open the editor’s Run and Debug controls and choose Python Debugger: Debug Python File.
  3. When execution pauses at a breakpoint, inspect variables and the call stack in the Debug view, then use the controls to step or continue.

For repeatable sessions or projects that need arguments, a particular working directory, or another launch setting, create a Python debugger configuration in .vscode/launch.json. Start debugging with F5. A Python File configuration is a starting point for a script; the workspace interpreter is used by default, and configuration options can select another interpreter. VS Code also documents attach-by-process-ID configurations. Exact options depend on the workflow; use the VS Code debugging reference when configuring a project.

Use debugpy from the command line

For command-line or remote workflows, install debugpy into the Python environment that will run the target:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m pip install --upgrade debugpy

Then invoke it with a listen or connect endpoint and the script, module, command, or process ID required by your setup. For example, to start a script with a local listener:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
python -m debugpy --listen 127.0.0.1:5678 path/to/script.py

The target waits for a debugger client to connect when configured to wait for that connection; consult the debugpy options shown by python -m debugpy --help for the exact flags supported by the installed version. In VS Code, configure an attach session with the same host and port. For a remote target, follow the documented remote-debugging setup and prefer a secure connection such as SSH where appropriate. Do not expose a debug listener to an untrusted network.

Debug a Python project in PyCharm

  1. Open the project and select the intended interpreter.
  2. Click the gutter beside a source line to set a breakpoint.
  3. Start the project using Debug, rather than the normal Run action.
  4. When execution pauses, inspect the suspended state and use the debugger controls to step or resume.

PyCharm’s help identifies debugpy as its default debugger for Python 3.9 or later with local and WSL interpreters; pydevd is an alternative. The coverage depends on the specific debugger and workflow. JetBrains lists scenarios not yet covered by debugpy, including some remote targets, attach-to-process, Sphinx doctest, Scrapy, remote Jupyter notebooks, and certain manage.py tasks. Remote DAP attachment and alternative debugger selection are separately documented paths. Check the current PyCharm documentation for your interpreter, framework, and deployment arrangement before depending on a specialized workflow.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common debugging problems and fixes

  • The breakpoint never triggers: confirm the program actually reaches that line, the file being executed is the file you edited, and the debugger is attached to the correct process. In an IDE, check that the selected interpreter and launch configuration match the project.
  • breakpoint() does not open pdb: the default breakpoint behavior can be changed through Python’s breakpoint configuration. Check the environment and runtime configuration, or launch explicitly with python -m pdb path/to/script.py.
  • VS Code uses the wrong Python environment: select the intended workspace interpreter and verify that required packages, including debugpy for its command-line workflow, are installed in that environment.
  • Attach fails or the remote session cannot connect: check the target host, port, process ID, and network route; ensure the client and target use compatible settings. Keep remote debug listeners off untrusted networks and use a secure tunnel such as SSH where appropriate.
  • pdb cannot attach to a Python 3.14 process: a process waiting on I/O or blocked in a system call may need to execute another bytecode instruction or receive a signal before attachment succeeds.
  • PyCharm’s selected debugger does not support the workflow: verify the documented debugpy coverage for the target interpreter and task, then assess whether the documented pydevd alternative or DAP path fits.
  • Stepping appears to skip code: next deliberately runs through a called function; use step when you need to enter it.

Or skip the browser setup

For debugging Python code, use the tools above. If your separate task is capturing a web page screenshot, ScreenshotNeo provides a screenshot API and MCP server for developers. One GET request returns an image or PDF; for example, this cURL command saves a WebP capture of Stripe:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for setup and options. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed; its MCP server lets AI agents take screenshots; and the free plan includes 1,000 screenshots a month with no card, while paid plans start at $5 for 3,000. Sign up for the free plan.

Frequently Asked Questions

Is pdb included with Python?

Yes. pdb is part of Python’s standard library, so a separate debugger installation is not required.

Can I debug a Python process that is already running?

Some workflows support attachment. Python’s pdb command-line PID attachment is documented for Python 3.14 and later; VS Code and PyCharm have their own attach paths with environment-specific qualifications.

Should I use step or next in pdb?

Use step to enter a called function and next to run over it without entering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.