2

I am trying to debug python code in vscode using a launch config that asks for command line arguments.

My script is located here:

C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python\my_script.py

and my test input file is here:

"C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\temp\test.txt"

The vscode launch.json is:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File with Arguments",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": "${command:pickArgs}"
        }
    ]
}

When I press F5 or click 'Run > Start Debugging', I get this popup in which I paste the fully qualified filename: command line argument dialog

after which the debug terminal below spits out the following:

PS C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python>  c:; cd 'c:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python'; c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\python.exe c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher 50410 -- C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python\my_script.py "C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\temp\test.txt" 
Traceback (most recent call last):
  File "c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy\__main__.py", line 71, in <module>
    cli.main()
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 508, in main
    run()
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 358, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 309, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 278, in _get_code_from_file        
    with io_open_code(decoded_path) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\USERNAME\\FolderName'
PS C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python> 

I assumed it was due to the fact that my test file was in a path with spaces, so I moved it and ran the script again so the argument no longer contained spaces: command line argument dialog

But I still got a similar error, as shown below:

PS C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python>  c:; cd 'c:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python'; c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\python.exe c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher 53983 -- C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python\my_script.py "C:\Users\USERNAME\Downloads\test.txt"
Traceback (most recent call last):
  File "c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy\__main__.py", line 71, in <module>
    cli.main()
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 508, in main
    run()
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 358, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 309, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 278, in _get_code_from_file        
    with io_open_code(decoded_path) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\USERNAME\\FolderName'
PS C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python> 

Looking more closely, it is now becoming apparent to me that the issue might be with the launcher, since I see in the output: no double quotes around script path and name

Trying to trace execution backwards, I think it might be braking here in cli.py: cli.py

because it does not appear to handle fully qualified paths with spaces. That is, when it executes, it has to call the script itself as an argument, and it appears to be the script argument that is not getting correctly wrapped in double quotes as it needs to be.

I am not 100% sure where exactly this should be fixed...

7
  • 2
    funny how Windows generalized the use of spaces in path and how a lot of tools are unable to support that. The plugin is clearly at fault. You can't really fix that at user level, unless you switch to paths without spaces. Commented Nov 7 at 6:29
  • 2
    While spaces in path and file names are not a Windows specific problem, they seem to bite Windows users disproportionately often. Commented Nov 7 at 6:37
  • @Jean-FrançoisFabre - windows paths can be expressed in "8.3" aka short path format which hopefully will not contain whitespaces so "user level" fix should be possible. See: superuser.com/questions/348079/… .. There's also powershell way to get that.. Commented Nov 7 at 9:45
  • 1
    the error is at line 1: c:; cd 'c:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python'; c:\Users\USERNAME\AppData\Local\Programs\Python\Python312\python.exe c:\Users\USERNAME\.vscode\extensions\ms-python.debugpy-2025.14.1-win32-x64\bundled\libs\debugpy\launcher 53983 -- C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python\my_script.py "C:\Users\USERNAME\Downloads\test.txt" as the script name here -- C:\Users\USERNAME\FolderName - With Spaces\_MyHome\Documents\Dev\Python\my_script.py isn't quoted properly. Python is not at fault here. Commented Nov 7 at 15:11
  • 1
    have you tried "program": "${file}", => "program": "\"${file}\"", in the json file? worth trying Commented Nov 7 at 15:13

1 Answer 1

0

From the callstack, it's clear that the plugin is at fault. It has a bug when it composes its command line by just joining arguments with spaces when it should protect them with quotes when necessary.

One working workaround (tested by OP) seems to be this:

In the json configuration file, change:

"program": "${file}"

by

"program": "\"${file}\""

so the executable path quoting is forced and the command line is correct.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't know why people down-voted this - your answer works, even though it is a workaround. The plugin indeed is at fault for not catering for paths that contain spaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.