Skip to content

Spaces in python interpreter path or program result in incorrectly quoted debugging commands with arguments #233

Closed

Description

@merely-present

Environment data

VS Code version: 1.86.2
Extension version: v2024.0.0
OS and version: Windows 10 Pro Up-to-date
Python version: 3.12
Shell: Powershell 7.4.1
Type of virtual environment used: venv with space in path.

Expected behaviour

The Python debugger should correctly quote paths that contain spaces in the Python interpreter path and the program to be debugged, ensuring commands are properly executed when arguments are taken through a launch.json configuration.

Actual behaviour

When there are spaces in the Python interpreter path or the program name, the debugger command fails due to improper quoting, leading to errors in execution.

For instance, if one's path for the interpreter were c:\Users\one\Documents\Python Folder\.venv\Scripts\python.exe, the error message they would receive would be

c:\Users\one\Documents\Python : The term 'c:\Users\one\Documents\Python' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Additional detail

Currently one can side step the program issue by using escaped quotes but I have not found a method to have the venv executables path be quoted correctly.

Steps to reproduce:

  • Create a Python file in a directory that has a space in its name.
  • Set up a virtual environment in a directory with a space in its name.
  • Configure launch.json to use the standard "Python Debugger: Current File with Arguments" like:
            {
                "name": "Python Debugger: Current File with Arguments",
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "args": "${command:pickArgs}"
            }
    
  • Start Debugging

Note: This also happens with manually hardcoded arguments.

Activity

  1. metamoof commented on Apr 5, 2024

    @metamoof

    Same thing is happening to me, both with type python and debugpy

  2. joeri-s commented on Apr 10, 2024

    @joeri-s

    Same issue here. My user folder (Windows 10) happens to contain spaces, which causes problems. It seems that the debugpy configuration with arguments is behaving differently than the "current file with no arguments" one. When running with default configuration in launch.json:

        {
            "name": "Python Debugger: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }

    The python executable and debugy launcher paths are wrapped in quotes, so it works. The following command is executed in PowerShell when running this configuration, and works: (note "User Name" with spaces)

    c:; cd 'c:\Path\Current\Directory'; & 'c:\Users\User Name\AppData\Local\Programs\Python\Python310\python.exe' 'c:\Users\User Name\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '52298' '--' 'C:\Local\my-repo\my-script.py'

    However, the configuration with arguments results in the following command being called, which is results in the same problem as the original ticket:

    c:\Users\User Name\AppData\Local\Programs\Python\Python310\python.exe c:\Users\User Name\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 52061 -- C:\Local\my-repo\my-script.py -i "input.txt"

    Wrapping the python.exe and debugpy/launcher paths in quotes here would solve the issue for users with spaces in their user folder path name.

  3. Poikilos commented on Apr 12, 2024

    @Poikilos

    Using launch.json, the problem only occurs in certain conditions (VSCode Version: 1.85.1 (Windows)):

    A. set args to a string args: "some_arg", I get the error, since it runs:

    • c:; cd 'c:\Users\redacted\git\blnk'; c:\Program Files\Python311\python.exe c:\Users\redacted\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 51463 -- some_script.py c:\Users\redacted\Desktop\some_file.txt

    B. set args to a list of strings args: ["some_arg"], error goes away since it runs (notice now it adds the single quotes around the python executable path in this case, unlike A above):

    • c:; cd 'c:\Users\redacted\git\blnk'; & 'c:\Program Files\Python311\python.exe' 'c:\Users\redacted\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '51492' '--' 'some_script.py' 'c:\Users\redacted\Desktop\some_file.txt'

    The terminal says it is running c:\Program Files\Python311\python.exe (with or without quotes depending on args setting for some reason, as described above)

    • python.pythonPath is python (no matter what I put there for folder or workspace, such as a full path, it is ignored)
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "some_script some_file.txt",
                "type": "debugpy",
                "request": "launch",
                "program": "some_script.py",
                "console": "integratedTerminal",
                "args": ["c:\\Users\\redacted\\Desktop\\some_file.txt"]
            }
        ]
    }
  4. boomshankerx commented on Apr 13, 2024

    @boomshankerx

    Confirmed.

    Version: 1.88.0 (system setup)
    Commit: 5c3e652f63e798a5ac2f31ffd0d863669328dc4c
    Date: 2024-04-03T13:26:18.741Z
    Electron: 28.2.8
    ElectronBuildId: 27744544
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Windows_NT x64 10.0.19045

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python Debugger: Current File with Arguments",
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "args": "${command:pickArgs}"
            }
        ]
    }
    
    PS R:\winscripts>  r:; cd 'r:\winscripts'; c:\Program Files\Python311\python.exe c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 42321 -- R:\winscripts\update-mod-date.py z:\files 
    c:\Program : The term 'c:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
    and try again.
    At line:1 char:26
    +  r:; cd 'r:\winscripts'; c:\Program Files\Python311\python.exe c:\Use ...
    +                          ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (c:\Program:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
  5. added
    bugIssue identified by VS Code Team member as probable bug
    needs PRReady to be worked on
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Apr 15, 2024
  6. peta909 commented on Apr 20, 2024

    @peta909

    this is an issue on OSX too. the following is a work around i used in my launch.json
    i hard coded the value for "program" with a file path and I added single quotes around the full path name.
    I hope the fix will be present soon. I just love to use VS Code!

    `{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python Debugger: Current File with Arguments",
            "type": "debugpy",
            "request": "launch",
            "program": "'/Users/user1/My folder/test.py'",
            "console": "integratedTerminal",
            "args": "-f '/Users/user1/My folder/test.bin'"
        }
    ]
    

    }`

    my setup
    Version: 1.88.1 (Universal)
    Commit: e170252f762678dec6ca2cc69aba1570769a5d39
    Date: 2024-04-10T17:42:52.765Z
    Electron: 28.2.8
    ElectronBuildId: 27744544
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Darwin x64 23.4.0

  7. da151575 commented on Apr 22, 2024

    @da151575

    Same issue on Windows 11. It was all running fine on some older version, hadn't written any python for a while, and I accepted the offer to upgrade everything when I fired up VSCode. Then suddenly I can't debug python anymore. Unfortunately I don't know which the old versions were. My setup is now:

    Windows 11 Version 23H2 (OS Build 22631.3447)
    Windows Powershell Version: 5.1.22621.2506
    VSCode Version: 1.88.1
    Python Extension version: v2024.4.1
    Python Debugger Extension version: v2024.4.0
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Python Debugger: Current File with Arguments",
    "type": "debugpy",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "args": "${command:pickArgs}"
    }
    ]
    }
    PS C:\Users\users\repos\usi-protocol> c:\Program Files\Python310\python.exe c:\Users\user.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 56240 -- C:\Users\user\repos\repo\code.py -a arg
    c:\Program : The term 'c:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:2

    • c:\Program Files\Python310\python.exe c:\Users\da151575.vscode\exte ...
    •  + CategoryInfo          : ObjectNotFound: (c:\Program:String) [], CommandNotFoundException
       + FullyQualifiedErrorId : CommandNotFoundException
      
      

    I don't know if it's the same cause, but this issue seems to be reported here (microsoft answers) and it is attributed to the Python extension rather than the debugger..? However the suggest workaround (roll back to an ancient version) no longer seems to work (it fails to install for me).

  8. Poikilos commented on Apr 23, 2024

    @Poikilos

    "args": "-f '/Users/user1/My folder/test.bin'"

    Since you have multiple arguments, list syntax (brackets around multiple comma-separated values) is what you should use (and served as a workaround in my case even when there is one argument). Thanks for the tip about the single quotes but see if this more typical syntax also works:

    "args": ["-f", "/Users/user1/My folder/test.bin"]
  9. SergeyZa commented on Apr 23, 2024

    @SergeyZa

    Jacob Gustafson (@Poikilos) The issue is not with args. Args is known by people, I hope. The issue with the path to python. I do not know how/where adjust that besides renaming folders. In my case a user name was created with space and it starts from there.

  10. Poikilos commented on Apr 23, 2024

    @Poikilos

    Jacob Gustafson (@Poikilos) The issue is not with args. Args is known by people, I hope. The issue with the path to python. I do not know how/where adjust that besides renaming folders. In my case a user name was created with space and it starts from there.

    Yes, I'm aware it is with the Python path, but in my case, changing the args syntax actually affected whether it could find Python. There is some type of cross-talk (command-splitting behavior changes for the whole command when the args is a string vs a list). My earlier comment gives an example, and may help the devs diagnose the issue.

  11. SergeyZa commented on Apr 23, 2024

    @SergeyZa

    Jacob Gustafson (@Poikilos) The issue is not with args. Args is known by people, I hope. The issue with the path to python. I do not know how/where adjust that besides renaming folders. In my case a user name was created with space and it starts from there.

    Yes, I'm aware it is with the Python path, but in my case, changing the args syntax actually affected whether it could find Python. There is some type of cross-talk (command-splitting behavior changes for the whole command when the args is a string vs a list). My earlier comment gives an example, and may help the devs diagnose the issue.

    Interesting... will try.

  12. 19 remaining items

  13. shinpei710 commented on Sep 11, 2024

    @shinpei710

    The setting, "${command:pickArgs}". Can it parse multiple args?
    I have tried many ways to input multiple args. But it always be one arg parsed into my program.

  14. eleanorjboyd commented on Dec 2, 2024

    @eleanorjboyd
    Contributor

    @xlbljz - since this is a long thread could you create a new issue in regards to this problem or ask in the discussions sections of this repo. Thanks!

  15. boomshankerx commented on Jul 19, 2025

    @boomshankerx

    This issue should not be closed. It still exists.

    c:\Program: The term 'c:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

  16. SiDtheTurtle commented on Sep 9, 2025

    @SiDtheTurtle

    Issue still exists. Workaround is, as per the above, add square brackets around the args in launch.json.

  17. doumeki commented on Sep 10, 2025

    @doumeki

    funny microsoft,the bug havent fix.

    workaround: use pythonPath:"python" instead python:xxx in launch.json. make sure the system env configed right python path before.

  18. KobeRiddle-dev commented on Oct 4, 2025

    @KobeRiddle-dev

    Can confirm, issue is still present. Spaces in the interpreter path (in this case, an interpreter in a venv) causes "path/until/space" to be executed.
    I've enabled the setting to use the environment manager as well.

  19. ssgen commented on Nov 28, 2025

    @ssgen

    What about if debugpy is installed in some user directory that has spaces ?
    Like:
    C:\Users<redacted user with spaces>.vscode\extensions\ms-python.debugpy-2025.16.0-win32-x64\bundled\libs\debugpy\launcher

    Launching without:
    "args": "${command:pickArgs}"
    correctly quotes python executable path and launcher path:
    & 'c:\<redacted path>\.venv\Scripts\python.exe' 'c:\Users\<redacted user>\.vscode\extensions\ms-python.debugpy-2025.16.0-win32-x64\bundled\libs\debugpy\launcher' '55936' '--' 'C:\<redacted script path>.py'

    Enabling the above destroys the quoting:
    c:\<redacted path>\.venv\Scripts\python.exe c:\Users\<redacted user>\.vscode\extensions\ms-python.debugpy-2025.16.0-win32-x64\bundled\libs\debugpy\launcher 57334 -- C:\<redacted script path>.py arg1 arg2 arg3

    Thanks for looking again into it.
    Better yet - where can I modify the quoting behaviour ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugneeds PRReady to be worked onverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions