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

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

Closed
fgiancane8 opened this issue May 29, 2024 · 9 comments
Closed
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@fgiancane8
Copy link

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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 29, 2024
@paulacamargo25
Copy link
Contributor

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

@paulacamargo25 paulacamargo25 added the info-needed Issue requires more information from poster label May 30, 2024
@fgiancane8
Copy link
Author

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
Copy link
Author

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
Copy link

roelandschoukens commented Jun 5, 2024

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
Copy link
Author

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

@fgiancane8
Copy link
Author

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

@paulacamargo25
Copy link
Contributor

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

@fgiancane8
Copy link
Author

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

If needed we can discuss further there.

Thanks!

@paulacamargo25
Copy link
Contributor

Thanks, closed as duplicated of: #233.

@paulacamargo25 paulacamargo25 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants