Python Debugging With pdb: Overview
Nowadays, we often take for granted the excellent debuggers built into our favorite IDEs. But how do you debug your Python code when you don’t have the luxury of using an IDE?
pdb
, short for Python DeBugger, is a module for interactive source code debugging. It’s built into the Python Standard Library, so it’s always accessible to you. Because it runs in the command line, it’s especially helpful when you’re developing on remote systems.
In this course, you’ll learn how to perform the most common debugging tasks using pdb
, including setting breakpoints, stepping through code, viewing stack traces, creating watch lists, and more.
Free Bonus: Click here to get a printable "pdb Command Reference" (PDF) that you can keep on your desk and refer to while debugging.
00:00 Imagine a world with no Visual Studio Code, no PyCharm, and not even good old fashioned IDLE. We can write Python code with command line tools like nano and VIM, and we can always run them through the command line, but how on earth are we supposed to actually debug them without these IDEs?
00:24 The answer is pdb. Hi, this is Austin Cepalia with realpython.com. In this course, we’re going to learn how to debug our Python programs with pdb. pdb, short for Python DeBugger, is a module for interactive source code debugging.
00:44 It’s built into the Python standard library, and so it’s always accessible for debugging your Python programs. If you’ve ever used the debugger in your favorite IDE before, a lot of the ideas we talk about in this course will be familiar to you.
01:00 pdb supports setting breakpoints, stepping through code, monitoring and even changing variables, and viewing stack traces. But pdb has got one major upside: it runs purely in the command line, similar to the Python interactive shell.
01:19 This makes it great for debugging code on remote servers, where we don’t always have the luxury of a GUI-based debugger. If you can run Python code from the command line, you can use pdb. Unless you are a hardcore programmer who lives and breathes VIM and believes it is a sin to take your hands off the keyboard, using pdb probably isn’t the most effective way of debugging. Sure, it works, but many people find it to be clunkier than its GUI-based counterparts, which can extend beyond the limitations of the command line.
01:56 But, as I mentioned before, there are scenarios where you can’t use a GUI-based debugger, and so pdb is a worthwhile tool to have in your programmer’s toolkit.
02:06 You never know when it’s going to come in handy. Finally, I should mention that pdb takes some practice before you can use it fluently. I’d highly recommend you follow along and make sure you fully understand what I’m doing before moving on to the next lesson. Let’s get started.
Become a Member to join the conversation.