microsoft / vscode-python-debugger

Python debugger (debugpy) extension for VS Code.
https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy
MIT License
40 stars 17 forks source link

Python Debugger fails to load Python3 if installed on a path with spaces #351

Closed fgiancane8 closed 2 weeks ago

fgiancane8 commented 1 month ago

Behaviour

It is expected to be able to debug a python script or module using the globally installed Python runtime from their website. It turns out that if installed via their setup, it gets deployed in C:\Program Files\Python312. The path contains a space which should be escaped when loading it, but it is not, resulting in misleading errors and not being able of debugging.

Steps to reproduce:

  1. Select "Start Debugging" (F5)
  2. Select "Python Debugger"
  3. Leave the command line empty
  4. Observe command line failure

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` PS C:\Users\fgiancan\source\repos\scripts> c:; cd 'c:\Users\fgiancan\source\repos\scripts'; c:\Program Files\Python312\python.exe c:\Users\fgiancan\.vscode\extensions\ms-python.debugpy-2024.6.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 63087 -- C:\Users\fgiancan\source\repos\scripts\test.py 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. ```

Output for Python Debugger in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Debugger)

``` 2024-05-29 12:34:57.789 [info] Experiment 'pythonRecommendTensorboardExt' is active 2024-05-29 12:34:57.789 [info] Experiment 'pythonREPLSmartSend' is active 2024-05-29 12:34:57.789 [info] Experiment 'pythonTerminalEnvVarActivation' is active 2024-05-29 12:34:57.789 [info] Experiment 'pythonTestAdapter' is active 2024-05-29 12:34:57.830 [info] Default formatter is set to null for workspace c:\Users\fgiancan\source\repos\scripts 2024-05-29 12:34:58.202 [info] > pyenv which python 2024-05-29 12:34:58.202 [info] cwd: . 2024-05-29 12:34:58.320 [info] > "c:\Program Files\Python312\python.exe" -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py 2024-05-29 12:35:01.402 [warning] Shell integration may not be active, environment activated may be overridden by the shell. 2024-05-29 12:35:02.368 [info] Python interpreter path: c:\Program Files\Python312\python.exe 2024-05-29 12:35:04.514 [info] Starting Pylance language server. 2024-05-29 12:35:06.331 [info] Shell integration status changed, can confirm it's working. 2024-05-29 12:40:58.375 [info] Python interpreter path: C:\Program Files\Python312\python.exe 2024-05-29 12:41:11.680 [info] Send text to terminal: c:\Program Files\Python312\python.exe c:\Users\fgiancan\.vscode\extensions\ms-python.debugpy-2024.6.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 63012 -- C:\Users\fgiancan\source\repos\scripts\test.py 2024-05-29 12:44:03.765 [info] Send text to terminal:  2024-05-29 12:44:03.765 [info] Send text to terminal: c:; cd 'c:\Users\fgiancan\source\repos\scripts'; c:\Program Files\Python312\python.exe c:\Users\fgiancan\.vscode\extensions\ms-python.debugpy-2024.6.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 63087 -- C:\Users\fgiancan\source\repos\scripts\test.py ```

paulacamargo25 commented 1 month ago

Thanks for your bug report, could you send me the value of config in the launch.json? Thanks

fgiancane8 commented 1 month ago

Sure, there you go. It's just the automatically-generated launch.json with an extended PYTHONPATH, nothing special.

{
    // 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",
            "justMyCode": false,
            "args": "${command:pickArgs}",
            "env": {
                "PYTHONPATH" : "${workspaceFolder}${pathSeparator}${env:PYTHONPATH}"
            }
        }
    ]
}
fgiancane8 commented 1 month ago

I think the issue is related to the fact that the interpreter's path string is taken and is left unquoted, and thus it is not parsed after encountering the first space character. That explains why "C:\Program Files\Python312\" is truncated to C:\Program.

roelandschoukens commented 4 weeks ago

You don’t need any launch.json file to reproduce this, just open a python file, press F5, select "Python File With Arguments", and you'll produce that error.

If you select "Python File" you'll see that the invocation on the PowerShell console has quotes:

'c:\Program Files\Python312\python.exe' 'path\to\launcher' '123456' '--' 'path\to\file.py'

If you select "Python File with Arguments" you'll see that none of the paths have quotes:

c:\Program Files\Python312\python.exe path\to\launcher 123456 -- path\to\file.py --a --b --c

(incidentally, to switch between those two, you'll need to do a "Python debugger: clear cache and reload window")

fgiancane8 commented 3 weeks ago

So this definitively confirms we have a bug here, right ?

fgiancane8 commented 3 weeks ago

@paulacamargo25 hello, Do we have an update on this?

paulacamargo25 commented 2 weeks ago

Thanks @fgiancane8 for the bug report, yes, could you confirm that this is a duplicate of #233.

fgiancane8 commented 2 weeks ago

Hello @paulacamargo25 , It looks like is the same issue.

If needed we can discuss further there.

Thanks!

paulacamargo25 commented 2 weeks ago

Thanks, closed as duplicated of: https://github.com/microsoft/vscode-python-debugger/issues/233.