Skip to content

Python extension does not detect Python installations and throws an error #16394

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

Closed
kwmlodozeniec opened this issue Jun 4, 2021 · 13 comments
Closed
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@kwmlodozeniec
Copy link

Environment data

  • VS Code version: 1.56.2
  • Extension version (available under the Extensions sidebar): XXX
  • OS and version: v2021.5.842923320
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.5, standard installation
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv and global installation
  • Value of the python.languageServer setting: Pylance
  • OS: Windows 10 1809 Build 17763.1935

Expected behaviour

The extension should correctly detect the installed python version without errors.

Actual behaviour

Extension fails to detect Python and throws an error in the output.
image

Steps to reproduce:

  1. Install python extension, open a python file.

Logs

Python extension output

Error 2021-06-04 16:23:57: Failed to get interpreter information for 'C:\Program Files\Python39\python.exe' [Error: Command failed: "C:\\Program Files\Python39\python.exe" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\interpreterInfo.py"
�[91mParserError: 
�[96mLine |
�[96m   1 | �[0m … python.exe" �[96m"c:\Users\mlodozk\.vscode\extensions\ms-python.python-202�[0m …
�[96m     | �[91m               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[91m�[96m     | �[91mUnexpected token
�[96m     | �[91m'"c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py"' in expression or statement.
�[0m

	at ChildProcess.exithandler (child_process.js:317:12)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1048:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: '"C:\\\\Program Files\\Python39\\python.exe" "c:\\Users\\mlodozk\\.vscode\\extensions\\ms-python.python-2021.5.842923320\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\mlodozk\\.vscode\\extensions\\ms-python.python-2021.5.842923320\\pythonFiles\\interpreterInfo.py"'
}
@kwmlodozeniec kwmlodozeniec added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jun 4, 2021
@kwmlodozeniec kwmlodozeniec changed the title Python extension does not detect Python installations and throws and error Python extension does not detect Python installations and throws an error Jun 4, 2021
@karthiknadig
Copy link
Member

Can you run this and share what you get?

"C:\Program Files\Python39\python.exe" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\interpreterInfo.py"

@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Jun 7, 2021

"C:\Program Files\Python39\python.exe" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\interpreterInfo.py"
ParserError:  
Line |
   1 |  … python.exe" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-202 …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unexpected token '"c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py"' in 
     | expression or statement.

Okay, I have run the above in powershell and this is where I get the issue. The standard cmd gives me this:

{"versionInfo": [3, 9, 5, "final", 0], "sysPrefix": "C:\\Program Files\\Python39", "sysVersion": "3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]", "is64Bit": true}

But this was working absolutely fine until now.

@karthiknadig karthiknadig added area-terminal triage and removed triage-needed Needs assignment to the proper sub-team labels Jun 7, 2021
@kwmlodozeniec
Copy link
Author

Is there anything else I could try to help debug the issue?

@karrtikr
Copy link

karrtikr commented Jun 9, 2021

We'll need to fix the error with powershell, it could be it's not able to parse certain unicode characters. What's the version of powershell you were using?

Did it ever used to work with the extension?
Can you try installing an older version of the extension (for example 2020.4.58038), and see if your problem happens?

You can follow the prompts from "Extensions: Install Specific Version of Extension..." in the command palette:

image

Or you can open the extensions side bar, click on the settings for the Python extension and pick "Install Another Version...":

https://user-images.githubusercontent.com/51720070/80000627-39dacc00-8472-11ea-9755-ac7ba0acbb70.gif

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jun 9, 2021
@kwmlodozeniec
Copy link
Author

My powershell version is 7.1.3
It used to work fine until a few weeks ago. I have tried a bunch of older version of the python extension without success, it's till reporting Python is not installed and not showing anything in the interpreter version in the status bar even when I select a new virtual env or point it to the system python installation.

@kwmlodozeniec
Copy link
Author

I even tried changing the default shell to cmd and VS Code is still trying to load the PS script activation file. Could that be a clue? I have changed the default shell to PS a few weeks ago, but I seem to remember it was working.

Microsoft Windows [Version 10.0.17763.1935]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\mlodozk\AppData\Roaming\Code\User>& c:/repos/automated-regression-testing/pysystemtests/.env/Scripts/Activate.ps1
& was unexpected at this time.

C:\Users\mlodozk\AppData\Roaming\Code\User>

@karrtikr
Copy link

karrtikr commented Jun 9, 2021

Oh I see, VSCode recently had a issue #16175 where the API was unable to detect the correct shell. Can you try VSCode insiders as mentioned here #16175 (comment) and see if it helps?

Either way, it seems the issue is either with powershell or VSCode, but not the extension itself as rolling back doesn't work.

@kwmlodozeniec
Copy link
Author

I tried the following insiders version and it still says Python is not installed.

Version: 1.57.0-insider (system setup)
Commit: b4c1bd0a9b03c749ea011b06c6d2676c8091a70c
Date: 2021-06-09T11:49:36.076Z
Electron: 12.0.9
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.17763

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Jun 10, 2021
@karrtikr
Copy link

As we can't pinpoint the source, let's try a few things:

  • For some reason powershell is used to run the commands when the default is cmd (Can you verify this using https://nodejs.org/api/child_process.html#child_process_default_windows_shell ?). Please paste your User settings which contain certain terminal settings impacting the shell type.
  • Looking at python.exe" �[96m"c:\Users\mlodozk\.vscode\extensions\ms-python.python-202�[0m and
"c:\Users\mlodozk\.vscode\extensions\ms-python.python-202 …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It seems the error has something to do with this path c:\Users\mlodozk\.vscode\extensions\ms-python.python-202. Can you move "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\pyvsc-run-isolated.py" out in some other location and then run

"C:\Program Files\Python39\python.exe" "new location of pyvsc-run-isolated.py" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.842923320\pythonFiles\interpreterInfo.py"

in powershell and see if the error goes.

  • Does downgrading powershell work?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jun 15, 2021
@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Jun 16, 2021

  1. COMSPEC output
C:\Users\mlodozk>echo %COMSPEC%
C:\Program Files\PowerShell\7\pwsh.exe

I think I have fixed that issue with VSCode defaulting to PS by removing my settings and adding them again. But here are my terminal related settings.

"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.profiles.windows": {
    "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell"
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [],
        "icon": "terminal-cmd"
    },
    "Git Bash": {
        "source": "Git Bash"
    },
    "PS": {
        "path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
    }
},
"C:\Program Files\Python39\python.exe" "c:\pyvsc-run-isolated.py" "c:\Users\mlodozk\.vscode\extensions\ms-python.python-2021.5.926500501\pythonFiles\interpreterInfo.py"
ParserError:  
Line |
   1 |  … Program Files\Python39\python.exe" "c:\pyvsc-run-isolated.py" "c:\Use … 
     |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unexpected token '"c:\pyvsc-run-isolated.py"' in expression or statement. 
  1. No, I still get the error on the previous version, 7.1.2, and I can confirm 7.1.3 has been working fine for a while already.

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Jun 16, 2021
@karrtikr
Copy link

Thanks for the info, this helps!

C:\Users\mlodozk>echo %COMSPEC%
C:\Program Files\PowerShell\7\pwsh.exe

So you have selected your default shell as powershell, we'll need to change that to cmd. Set the environment variable to contain the full path to cmd instead. (It's probably C:\WINDOWS\System32\cmd.exe) Once you do that I expect the extension to start working.

As for the powershell issue, that is something you'll need to find a fix for yourselves as it's unrelated to the extension.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jun 16, 2021
@kwmlodozeniec
Copy link
Author

Thanks for that, correcting the comspec fixed my issue with the extension!

@karrtikr
Copy link

Great, closing this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants