8) Debugging Lesson

Python Debugger in IDE

4 min to complete · By Martin Breuss

You'll spend a lot of your time as a developer debugging code. That's why more professional text editors and IDEs usually include an integrated debugger.

From seeing the more visual debuggers, such as pudb and web-pdb you're already familiar with the general idea of an interface that these visual debuggers provide. You can do everything that you did with the pdb-based debuggers, and often much more.

Colorful illustration of a light bulb

Info: IDEs with integrated debuggers usually also include a visual way to set breakpoints so that you don't need to add any additional lines of code into your script. In VS Code, you can do this by clicking on the margin next to the line numbers.

As an example of a professional integrated debugger, you'll take a look at the one that comes with VS Code.

Accessing the Debugger in VS Code

To access VS Code's debugger, you can press the dropdown next to the Play symbol on the top-right corner of the app, then select Debug Python File:

Dropdown to access VS Code

Alternatively, you can also access it by opening the command palette by pressing Cmd+Shift+p on macOS, or Ctrl+Shift+p on Linux and Windows, typing debug, and pressing Enter:

Start Debugging in VS Code via the command palette

This will execute your script as a debugging session, which means that any visual breakpoints you set in the margins of your script will take effect. The built-in debugger will stop execution at the breakpoints and launch the interactive session.

Interacting with VS Code's Debugger

VS Code's debugger allows you to visually set breakpoints, step through execution, inspect all current variable values, and more.

However, just like the visual debuggers you've encountered in the previous lesson, it works in a more user-friendly manner. You have access to buttons instead of text commands.

You'll also notice the Variables panel and how it displays the current variable values. VS Code's debugger also uses color-highlighting to show eventual changes:

VS Code

Don't get overwhelmed if there seems to be too much lot going on. Try to focus on what you're interested in right now and recreate the more basic functionality of pdb. You can keep learning your built-in debugger slowly while you continue to develop more and more complex programs.

Colorful illustration of a light bulb

Additional Resources

Summary: Python, Debugger in IDE

  • Professional IDEs and text editors often come with built-in debuggers that give you even more functionality than the debuggers you've encountered before.
  • To access VS Code's debugger, you can press the dropdown next to the Play symbol on the top-right corner of the app, then select Debug Python File
  • VS Code's debugger allows you to visually set breakpoints, step through execution, inspect all current variable values, and more.