TIL Debug any python file in VS Code

December 21, 2022

One of my frustrations with VisualStudio Code was creating a launch.json file whenever I wanted to debug a one-off Python file.

Today, I learned that you could add a debugger configuration to your user settings. This allows you always to have a debugging configuration available.

How to do this

Create a debugging (or launch) configuration:

  1. Select the “Run and Debug” tab and click “create a launch.json file”

A screen capture that shows a VisualStudio Code window with  the “Run and Debug” pane active. The link to create a launch.json file is highlighted.

2. Choose “Python File”

3. VS Code will generate a configuration for you. This is the one I used, where I changed the "justMyCode" to false , so I can step in to any Python code.

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "justMyCode": false
}

4. Copy the config (including the curly braces)

5. Open your user configuration ( / Ctrl + , ) and search for “launch”.

6. Click “Edit in settings.json”

7. Add your configuration to the "configurations" list.

This is what mine looks like, for reference:

...
"launch": {
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ],
    "compounds": []
}

© 2024 Everyday Superpowers

LINKS
About | Articles | Resources

Free! Four simple steps to solid python projects.

Reduce bugs, expand capabilities, and increase your confidence by building on these four foundational items.

Get the Guide

Join the Everyday Superpowers community!

We're building a community to help all of us grow and meet other Pythonistas. Join us!

Join

Subscribe for email updates.