Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CS-Account opened this issue Feb 25, 2024 · 14 comments · Fixed by #385
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Milestone

Comments

@CS-Account
Copy link

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.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 25, 2024
@metamoof
Copy link

metamoof commented Apr 5, 2024

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

@joeri-s
Copy link

joeri-s commented Apr 10, 2024

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.

@Poikilos
Copy link

Poikilos commented Apr 12, 2024

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"]
        }
    ]
}

@boomshankerx
Copy link

boomshankerx commented Apr 13, 2024

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

@paulacamargo25 paulacamargo25 added bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Apr 15, 2024
@peta909
Copy link

peta909 commented Apr 20, 2024

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

@da151575
Copy link

da151575 commented Apr 22, 2024

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).

@Poikilos
Copy link

Poikilos commented Apr 23, 2024

"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"]

@SergeyZa
Copy link

@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.

@Poikilos
Copy link

@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.

@SergeyZa
Copy link

@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.

@da151575
Copy link

da151575 commented Apr 24, 2024

@Poikilos Yes, interesting - I can confirm that this works for me:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
},
{
"name": "Python Debugger: Program with Arguments",
"type": "debugpy",
"request": "launch",
"program": "program.py",
"console": "integratedTerminal",
"args": ["-a", "arg"]
}
]
}
PS C:\Users\user\repos\repo> c:; cd 'c:\Users\user\repos\repo'; & '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' '56396' '--' 'program.py' '-a' 'arg'

This is working for me....

@tjohnsonhvac
Copy link

I found a fix!!

Auto-generated debug configuration fails:
image

Changing the args to an array fixes it...
image

@Poikilos
Copy link

Poikilos commented May 3, 2024

I found a fix!!

@tjohnsonhvac Thanks, but lol, same as my workaround cited in da151575's comment directly before yours 😆. To bump the issue maybe instead say "issue and workaround confirmed in version ..." and/or add thumbs up the issue.

@Yases-spec
Copy link

Captura de tela 2024-07-16 102058
any solution? same erro, i think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.