Specify the module you want to run with "module": "torch.distributed.launch"

You can ignore the -m flag. Put everything else under the args key.

Note: Make sure to include --nproc_per_node and the name of file (main_swav.py) in the list of arguments

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "debugpy",
            "module": "torch.distributed.launch",
            "request": "launch",
            "console": "integratedTerminal",
            "args": [
                "--nproc_per_node", "1", 
                "main_swav.py",
                "--data_path", "/dataset/imagenet/train",
            ]
        }
    ]
}

Read more here: https://code.visualstudio.com/docs/python/debugging#_module

Answer from Matt Spataro on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Python Debugger: Debug Python File.
🌐
Medium
sanborse.medium.com › debugging-python-script-in-vscode-e865b7d6dab5
Debugging Python Script in VSCode | by Santosh Borse | Medium
September 30, 2021 - I started with simple python code file — sample-debug.py · Click on “Run and Debug” button ( on leftmost pane ) and click a link “create a launch.json file”, and select workspace of folder to save launch.json and select Python file,
Discussions

Visual Studio Code: How debug Python script with arguments - Stack Overflow
I'm using Visual Studio Code with the inbuilt Debugger in order to debug a Python script. Following this guide, I set up the argument in the launch.json file: But when I press on Debug, it says th... More on stackoverflow.com
🌐 stackoverflow.com
Debugging an active python file that creates launch.json is debugging launch.json
Testing #141 Install the debugpy and python extensions Open a folder that has python file. Open the python file. Make sure that you don't have a launch.json config already set. On the top right you will see a play button with an arrow, c... More on github.com
🌐 github.com
0
November 28, 2023
debugging - How to step through Python code to help debug issues? - Stack Overflow
In Java/C# you can easily step through code to trace what might be going wrong, and IDE's make this process very user friendly. Can you trace through python code in a similar fashion? More on stackoverflow.com
🌐 stackoverflow.com
How to debug a Python module in Visual Studio Code's launch.json - Stack Overflow
My question may seem simple but, I have a module that I launch in a terminal like this: python -m my_module.my_file How do I debug this in Visual Studio Code? I have this in my launch.json ( More on stackoverflow.com
🌐 stackoverflow.com
September 15, 2025
🌐
Towards Data Science
towardsdatascience.com › home › latest › a comprehensive guide to debugging python scripts in vs code
A comprehensive guide to debugging Python scripts in VS Code | Towards Data Science
March 5, 2025 - Alternatively, we can use the launch.json config file to provide a set of env variables to the debugging environment. To do so, we press the "gear" icon to open the file and modify it by adding the contents of line 10. When we run the next debugging session, we can directly access the RUN_TYPE env variable, for example, by running the following two lines: ... In this article, I showed how to quickly use VS Code for debugging Python scripts...
🌐
Python Land
python.land › home › creating python programs › python in vscode: running and debugging
Python in VSCode: Running and Debugging • Python Land Tutorial
September 5, 2025 - { "version": "0.2.0", "configurations": [ { "name": "Run with argument", "type": "python", "request": "launch", "program": "vscode_playground.py", "console": "integratedTerminal", "args": ["Erik"] } ] }Code language: JSON / JSON with Comments (json) This configuration supplies an argument to the script: the name ‘Erik’. Note that it also specifically starts vscode_playground.py instead of the current file. You can now launch the debugger using this configuration.
🌐
Towards Data Science
towardsdatascience.com › home › latest › debug python scripts like a pro
Debug Python Scripts Like a Pro | Towards Data Science
March 5, 2025 - You’ll see a new JSON file open up with some familiar options. Overriding debug configuration in VSCode – Image by Author · The above file runs the ‘manage.py’ file in the ${workspacefolder} (that’s the root of the project you’ve opened in VSCode). In addition, it takes a command-line argument ‘runserver.’ · What it means is it’s about to execute python manage.py runserver when the debugger starts.
Find elsewhere
🌐
Sentry
blog.sentry.io › debugging-python-with-vs-code-and-sentry
Debugging Python with VS Code and Sentry | Sentry
December 13, 2024 - VS Code is now set up to debug the Python script. To launch the script in debugging mode, click the green arrow at the top of the Run and Debug sidebar or press F5 on your keyboard.
🌐
GitHub
github.com › microsoft › vscode-python-debugger › issues › 142
Debugging an active python file that creates launch.json is debugging launch.json · Issue #142 · microsoft/vscode-python-debugger
November 28, 2023 - A prompt is displayed. Select Python Debugger and in the next prompt select Python File 🐛 Launch.json is created and opened. Python Debugger runs and debug the launch file.
Author   sandy081
Top answer
1 of 15
409

Yes! There's a Python debugger called pdb just for doing that!

You can launch a Python program through pdb via python -m pdb myscript.py.

There are a few commands you can then issue, which are documented on the pdb page.

Some useful ones to remember are:

  • b: set a breakpoint
  • c: continue debugging until you hit a breakpoint
  • s: step through the code
  • n: to go to next line of code
  • l: list source code for the current file (default: 11 lines including the line being executed)
  • u: navigate up a stack frame
  • d: navigate down a stack frame
  • p: to print the value of an expression in the current context

If you don't want to use a command line debugger, some IDEs like Pydev, Wing IDE or PyCharm have a GUI debugger. Wing and PyCharm are commercial products, but Wing has a free "Personal" edition, and PyCharm has a free community edition.

2 of 15
87

By using Python Interactive Debugger 'pdb'

First step is to make the Python interpreter enter into the debugging mode.

A. From the Command Line

Most straight forward way, running from command line, of python interpreter

$ python -m pdb scriptName.py
> .../pdb_script.py(7)<module>()
-> """
(Pdb)

B. Within the Interpreter

While developing early versions of modules and to experiment it more iteratively.

$ python
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb_script
>>> import pdb
>>> pdb.run('pdb_script.MyObj(5).go()')
> <string>(1)<module>()
(Pdb)

C. From Within Your Program

For a big project and long-running module, can start the debugging from inside the program using import pdb and set_trace() like this:

#!/usr/bin/env python
# encoding: utf-8
#

import pdb

class MyObj(object):
    count = 5
    def __init__(self):
        self.count= 9

    def go(self):
        for i in range(self.count):
            pdb.set_trace()
            print i
        return

if __name__ == '__main__':
    MyObj(5).go()

Step-by-Step debugging to go into more internal

  1. Execute the next statement… with “n” (next)

  2. Repeating the last debugging command… with ENTER

  3. Quitting it all… with “q” (quit)

  4. Printing the value of variables… with “p” (print)

    a) p a

  5. Turning off the (Pdb) prompt… with “c” (continue)

  6. Seeing where you are… with “l” (list)

  7. Stepping into subroutines… with “s” (step into)

  8. Continuing… but just to the end of the current subroutine… with “r” (return)

  9. Assign a new value

    a) !b = "B"

  10. Set a breakpoint

    a) break linenumber

    b) break functionname

    c) break filename:linenumber

  11. Temporary breakpoint

    a) tbreak linenumber

  12. Conditional breakpoint

    a) break linenumber, condition

Note: All these commands should be executed from pdb

For in-depth knowledge, refer:

  • https://pymotw.com/2/pdb/

  • https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/

🌐
Qodo
qodo.ai › blog › learn › tutorial: how to debug python code in visual studio code
Tutorial: How to Debug Python code in Visual Studio Code - Qodo
September 17, 2025 - This configuration packs the essentials: it uses debugpy (VS Code’s Python debugger), launches your current file, and runs it in the integrated terminal. { "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] } Want more powerful controls? Add these options to your configuration: ‘args’: Pass command-line arguments to your script
🌐
YouTube
youtube.com › watch
Debugging Python with Visual Studio Code (VSCode) - YouTube
In this tutorial, we will guide you through the process of debugging Python code with Visual Studio Code (VSCode). VSCode is a popular code editor with debug...
Published   April 19, 2023
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 5580830 › how-to-fix-vs-code-debug-failure-for-python
How to fix VS code debug failure for python - Microsoft Q&A
August 25, 2025 - two properly debug your script in VS code, you need to tell the debugger about arguments to pass through your script by modifying your launch.json file. ... b. find the relevant configuration for running the current file(it should look similar to the example you posted with “name”:” Python: current file”).
🌐
Reddit
reddit.com › r/pycharm › in the debugger i often have to convert python dict to json is there a better way than evaluate expression with json.dumps()?
r/pycharm on Reddit: In the debugger I often have to convert python dict to json is there a better way than evaluate expression with json.dumps()?
March 9, 2023 -

As the title says I often need to convert the value of a variable in the debugger to json for other purposes. So I use the evaluate expression function and type

import json
j = json.dumps(my_dict)

Then I copy the value of that "j" var to my clipboard.

I would think there should be an easier way so I don't have to repeat this over and over? I messed around int he "Customize Data View" but I couldn't get it to work the way I expected. I tried a macro but can't quite get it right. I'd like the macro to copy the name of the dict I am currently selecting dump it to json and copy the output of the dump to my clipboard.

Any info on a better way of doing this is greatly appreciated

🌐
Python
docs.python.org › 3 › library › pdb.html
pdb — The Python Debugger
The debugger’s prompt is (Pdb), which is the indicator that you are in debug mode: > ...(2)double() -> breakpoint() (Pdb) p x 3 (Pdb) continue 3 * 2 is 6 · Changed in version 3.3: Tab-completion via the readline module is available for commands and command arguments, e.g. the current global and local names are offered as arguments of the p command. You can also invoke pdb from the command line to debug other scripts.
🌐
Medium
medium.com › @jonathan_b › debugging-in-visual-studio-code-a-python-app-with-arguments-8d75a69bbd66
Debugging in Visual Studio Code — A Python app with arguments | by BLAKELY | Medium
October 9, 2025 - To create a launch.json file, click debug and run and click the textual link, create a launch.json file . ... Select Python Debugger from the Command Palette. From the list of debug configurations that appear, select thePython file with arguments ...