Skip to content

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

Closed

Description

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

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Jun 4, 2021
  2. 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[/+] on Jun 4, 2021
  3. karthiknadig commented on Jun 4, 2021

    @karthiknadig
    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"
    
  4. kwmlodozeniec commented on Jun 7, 2021

    @kwmlodozeniec
    Author
    "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.

  5. kwmlodozeniec commented on Jun 9, 2021

    @kwmlodozeniec
    Author

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

  6. karrtikr commented on Jun 9, 2021

    @karrtikr

    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

  7. kwmlodozeniec commented on Jun 9, 2021

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

  8. kwmlodozeniec commented on Jun 9, 2021

    @kwmlodozeniec
    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>
    
  9. karrtikr commented on Jun 9, 2021

    @karrtikr

    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.

  10. kwmlodozeniec commented on Jun 10, 2021

    @kwmlodozeniec
    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
    
  11. karrtikr commented on Jun 15, 2021

    @karrtikr

    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?
  12. kwmlodozeniec commented on Jun 16, 2021

    @kwmlodozeniec
    Author
    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.
  13. karrtikr commented on Jun 16, 2021

    @karrtikr

    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.

  14. kwmlodozeniec commented on Jun 18, 2021

    @kwmlodozeniec
    Author

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

  15. karrtikr commented on Jun 18, 2021

    @karrtikr

    Great, closing this.

  16. locked as resolved and limited conversation to collaborators on Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions