How to fix VS code debug failure for python

Farhan Segujja 0 Reputation points
2025-10-10T05:50:53.7633333+00:00

User's image

This is what my VS code is displaying even when i try to debug a simple python file of print("Hello World"). I have used Vs code for about a year now and it has never happened. I even re-installed it but it still displays the same. I have even changed the launch.json configurations to those recommended by CO-PILOT but all in vain. I even re-installed the extensions. However, the program runs well. {Python Programmer here}

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. kestutis cerniauskas 0 Reputation points
    2025-10-10T07:25:39.6633333+00:00

    I rolled back Python Debugger extension to 2025.10, and it started working.

    0 comments No comments

  2. David Cleland 0 Reputation points
    2025-10-10T13:51:24.1766667+00:00

    I literally just hit this while investigating a separate Python debug bug.

    As others have said rolling back to the 2025.10 Python Debugger extension fixed the problem.

    0 comments No comments

  3. Adiba Khan 895 Reputation points Microsoft External Staff
    2025-10-17T09:57:03.8133333+00:00

    Thank you for reaching out. Here are some steps that you can follow to resolve this issue:

    1.      verify Python and VS code setup

    ·         Check Python installation

    open a terminal in VS code end run:

      python --version

    or

                        py --version
    

    Ensure Python is correctly installed and added to your system path.

    ·         Check Python environment

                                                                  i.      open the command palette(ctrl+shift+P)

                                                                ii.      select Python: select interpreter

                                                              iii.      choose the correct environment (e.g., your actual virtual environment or system interpreter)

    2.      Reinstall debugger extension

    ·         Open extensions (ctrl+shift+X)

    ·         Search for Python (by Microsoft)

    ·         Click uninstall-> restart VS code-> reinstall it again

    (this reinstalls the integrated debugger adapter)

    3.      reset or recreate launch.json

    ·         Delete the existing .vscode/launch.json  file in your project folder.

    ·         Press F5 (start debugging)-> vs code will automatically prompt to create a new debug configuration.

    ·         Choose Python file as the configuration type.

    ·         Example of working launch.json

    {

    “version”:”0.2.0”,

    “configurations”:[

    {

                    “name”: “Python: current File”,

                    “type”: “python”,

                    “request”: “launch”,

                    “program”: “${file}”,

                    “console”: “integratedTerminal”

    }

    ]}

    4.      Disable third party extension

    some extensions (like copilot or custom formatters) can interfere with the debug adapter.

    Try launching vs code with extension disabled:

    Code --disable-extensions

    Then test debugging again.

    5.      Check debug console for logs

    go to view-> output -> Python debugger and check for any detailed error messages if the debugger adapter fails to start, it will log the issue here.

    6.      Optional- reset vs code user data

    if the problem persists you can reset vs code settings to default:

    ·         Close VS code.

    ·         Delete this folder: %APPDATA%\Code

    ·         Restart vs code and reinstalled the Python extension.

    7.      Verify with minimal repro

    create a new folder, add a single file test.py:

    print(“Hello World”)

    Open the folder in VS code and press F5. If debugging works here, the issue is likely project is specific(e.g., old .vscode config or extension conflicts).

     

    Reference docs:

    ·         Debug Python code, set breakpoints, inspect code - Visual Studio (Windows) | Microsoft Learn

    ·         Debug code with Visual Studio Code

    Python - Visual Studio Marketplace

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.


  4. Adiba Khan 895 Reputation points Microsoft External Staff
    2025-10-20T12:00:04.0433333+00:00

    Thank you for providing the additional context and the error trace back. The core of the problem is not a VS code setup failure but a runtime error in your Python code that is exposed when the VS code debugger attempts to execute the file.

    Analysis of the error traceback

    the last line of the traceback image is the key: IndexError: list assignment index out of range (the full error seems to be IndexError : list index out of range and it is happening on a line related to sys.argv).

    A trash back further up shows the code attempting to access sys.argv:

    IndexError: list index out of range

    the root cause: sys.argv is missing arguments

    the sys.argv list in Python contains the command line argument passed to a script.

    ·         Sys.argv[0] is always the name of the script (e.g., ‘renamer.py’).

    ·         Sys.argv[1] Is the first argument provided after the script name.

    ·         Sys.argc[2] is the second argument and so on.

    The indexerror occurs because your script(likely the file name renamer.py visible in the tracebacl) is trying to access an element of sys.argv at an index that doesn't exist, such as sys.argv[1] or sus.argv[2], but no corresponding argument was passed to the script when you started the debugger. When you run a script without arguments, sys.argv only contains one element: sys.argv[0].

     The previous “debug stopped” after you were seeing was likely the debugger halting because of this unhandled exception. The program runs successfully when you execute it without the debugger because you are providing the necessary command line arguments via the terminal, but the debugger needs to be explicitly told what arguments to use.

    Fixing the debug configuration:

    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.

    1.      Modify launch.json to pass arguments

    a.      open your .vscode/launch.json in your project folder

    b.     find the relevant configuration for running the current file(it should look similar to the example you posted with “name”:” Python: current file”).

    c.      Add or modify the “args” property. This property takes a list of strings, where each string is a separate command line argument your script needs.

    Example modification(assuming your script needs one or two arguments);

                   { “version “: “0.2.0”,
    
                    “configurations”: [
    
                     {
    
                       “name”: “Python: Current File with args”,
    
                       “type”: “python”,
    
                       “request”:”launch”,
    
                       “program”:”${file}”,
    
                       “console”: “integratedTerminal”,
    
                        // >>> ADD THIS SECTION<<<
    
                       “args”: [
    

            “C:/path/to/my/input_folder”,

            “C:/path/to/my/output_file.txt”

                      ],
    
                     // >>> END OF ADDITION <<<
    

            “justMyCode”: true

                     }
    
                                           ]
    
                     }
    

    ·         Action: replace “C:/path/to/my/input_folder”, and “C:/path/to/my/output_file.txt” with the actual arguments(file path, names etcetera) that your script needs to run successfully

    ·         Note on sys.argv: the first item in the “args” list will be accessible as sys.argv[1], the second as sys.argv[2] and so on

    2.      Verify your Python code (if arguments are optional)

    if your script should be able to run without arguments (e.g., if you are just testing print(“Hello”)), the IndexError means you are a script is accessing sys.argc1] or another index without checking if the argument was provided.

    Self correction in Python: Wrap your argument access with a check for the length of  sys.argv.

     

                    Import sys
    
                   # Check if the minimum required arguments are present
    
                   If len(sys.argv)>1:
    

                    Firsy_arg = sys.argv[1]

                    #... use first_arg

                   Else:
    

                    Print(“error: Please provide at least one command line argument.”)

                    # or assign a default value

                    First_arg = “default_value”

    Conclusion

    the problem is almost certainly due to missing command line arguments in the debugger's configuration, not a bug in the vs code debugger or a Python version issue. Modifying the “args” add it in your launch.json will resolve the IndexError: list index out of range


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.