Skip to content

Python Interpreter selection not working even though a version is being selected manually #18138

Closed

Description

VS Code version

1.62.3

Extension version

v2021.11.1422169775

OS type

Windows

OS version

Windows 10

Python distribution

python.org

Python version

3.10.1

Language server

Pylance

Expected behaviour

The Python Interpreter should be selected but none is being selected.

Actual behaviour

error

This is what happens when I try to select an interpreter. I can not click on the menu either it just does not do anything. When I click the arrow keys to move it, it glitches out like what is seen. Below is what I have tried.

-Reinstalling VSC and Python
-Trying Different Python Versions

Steps to reproduce

This started to happen when I booted up VSC yesterday I do not know how to reproduce it.

Logs

image

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. cjcocokrisp commented on Dec 8, 2021

    @cjcocokrisp
    Author

    I just went to mess around with installing older versions and the select interpreter is no longer there and Python 3.10.1 64-Bit is now displayed but now I am getting an error that is saying Python is not installed. I tried all of the 2021 version but it started working when I tried v2020.1.57204.

  2. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    Can you see what you get when you run "C:\Program files\Python310\python.exe" %USERPROFILE%\.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\interpreterInfo.py and see what you get? it should print a JSON with some data about the python.

    If it is printing out JSON, can you set the python logging level in settings to debug and restart and share the entire log:
    image

  3. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    Is this correct?

    image

  4. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    @cjcocokrisps that seems to be right can you share the full logs.

  5. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    how do i get that?

  6. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    Ensure that logging is set to debug:
    image

    Reload VS Code, using the Developer: reload window command:
    image

    Open a Python file, and wait for the extension to load. Repro the problem, then copy paste the contents of the text here:
    image

  7. added
    area-environmentsFeatures relating to handling interpreter environments
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Dec 9, 2021
  8. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author
    [DEBUG 2021-11-9 14:47:15.895]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="global"-Arg-Separator-"WORKSPACE_FOLDER_INTERPRETER_PATH_C:\\USERS\\CHRISTOPHER\\.VSCODE"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:15.895]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="workspace"-Arg-Separator-"autoSelectedWorkspacePythonInterpreter-c:\\Users\\Christopher\\.vscode"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:26.580]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="global"-Arg-Separator-"WORKSPACE_FOLDER_INTERPRETER_PATH_C:\\USERS\\CHRISTOPHER\\.VSCODE"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:26.580]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="global"-Arg-Separator-"WORKSPACE_FOLDER_INTERPRETER_PATH_C:\\USERS\\CHRISTOPHER\\.VSCODE"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:26.594]: Cached data exists getEnvironmentVariables, c:\Users\Christopher\.vscode
    [INFO 2021-11-9 14:47:26.601]: > python -c "import sys;print(sys.executable)"
    > python -c "import sys;print(sys.executable)"
    [DEBUG 2021-11-9 14:47:26.676]: Cached data exists getEnvironmentVariables, <No Resource>
    [INFO 2021-11-9 14:47:26.676]: > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
    > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
    [DEBUG 2021-11-9 14:47:26.679]: [Error: spawn cmd.exe ENOENT
    	at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    	at onErrorNT (internal/child_process.js:465:16)
    	at processTicksAndRejections (internal/process/task_queues.js:80:21)] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'spawn cmd.exe',
      path: 'cmd.exe',
      spawnargs: [
        '/d',
        '/s',
        '/c',
        '""C:\\Users\\Christopher\\AppData\\Local\\Programs\\Python\\Python310\\python.exe" "c:\\Users\\Christopher\\.vscode\\extensions\\ms-python.python-2021.12.1559732655\\pythonFiles\\interpreterInfo.py""'
      ],
      cmd: '"C:\\Users\\Christopher\\AppData\\Local\\Programs\\Python\\Python310\\python.exe" "c:\\Users\\Christopher\\.vscode\\extensions\\ms-python.python-2021.12.1559732655\\pythonFiles\\interpreterInfo.py"'
    }
    [DEBUG 2021-11-9 14:47:37.535]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="global"-Arg-Separator-"WORKSPACE_FOLDER_INTERPRETER_PATH_C:\\USERS\\CHRISTOPHER\\.VSCODE"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:37.535]: Cached data exists KeyPrefix=Cache_Method_Output_p.addKeyToStorage-Args="global"-Arg-Separator-"WORKSPACE_FOLDER_INTERPRETER_PATH_C:\\USERS\\CHRISTOPHER\\.VSCODE"-Arg-Separator-undefined
    [DEBUG 2021-11-9 14:47:37.541]: Cached data exists getEnvironmentVariables, extension-output-ms-python.python-#1
    [INFO 2021-11-9 14:47:37.545]: > python -c "import sys;print(sys.executable)"
    > python -c "import sys;print(sys.executable)"
    [DEBUG 2021-11-9 14:47:37.593]: Cached data exists getEnvironmentVariables, <No Resource>
    [INFO 2021-11-9 14:47:37.593]: > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
    > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
    [DEBUG 2021-11-9 14:47:37.595]: [Error: spawn cmd.exe ENOENT
    	at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    	at onErrorNT (internal/child_process.js:465:16)
    	at processTicksAndRejections (internal/process/task_queues.js:80:21)] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'spawn cmd.exe',
      path: 'cmd.exe',
      spawnargs: [
        '/d',
        '/s',
        '/c',
        '""C:\\Users\\Christopher\\AppData\\Local\\Programs\\Python\\Python310\\python.exe" "c:\\Users\\Christopher\\.vscode\\extensions\\ms-python.python-2021.12.1559732655\\pythonFiles\\interpreterInfo.py""'
      ],
      cmd: '"C:\\Users\\Christopher\\AppData\\Local\\Programs\\Python\\Python310\\python.exe" "c:\\Users\\Christopher\\.vscode\\extensions\\ms-python.python-2021.12.1559732655\\pythonFiles\\interpreterInfo.py"'
    }```
    
  9. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    Can you try running this from the terminal? The logs seem to suggest this is failing to run.

    "C:\Users\Christopher\AppData\Local\Programs\Python\Python310\python.exe" "c:\Users\Christopher\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py"
    
  10. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    image

  11. 6 remaining items

  12. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    Run this command, from the same prompt:
    C:\Users\Christopher\AppData\Local\Programs\Python\Python310\python.exe "c:\Users\Christopher.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py"

  13. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    Probably input something wrong?

    image

  14. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    You are missing a \ before .vscode.

  15. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    image

  16. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    From what I can tell, this error Error: spawn cmd.exe ENOENT is due to VS Code not being able to find cmd.exe. Can you make sure that the path printed out by set ComSpec, matches the location of cmd.exe? Error: spawn cmd.exe ENOENT is the cause of why the extension is not allowing you to pick anything.

  17. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    cmd.exe is located in my C:\Windows\System32\ the one on set ComSpec is a lowercase s I'm assuming that might be causing the problem then. If that's the case then how would I go about fixing that?
    image

  18. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    Unless you have enabled case sensitive paths on windows that should not be causing this. I don't think that is the issue.
    What do you get when you run set PATH?

    If you really want to try it, see this:
    image

    image

  19. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    image

  20. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    @cjcocokrisps Found the problem, your PATH looks wrong. This is what it typically looks like:
    image

    See that C:\Windows\System32 is the first entry. I am not sure how it got this way, but this can break a lot of things on Windows.

    You can use the environments variable editor to fix your problem. make sure that system32 is at the top of the list:
    image

    Fix that, then close and re-open all instances of VS Code.

    I am closing this issue since it is not a python extension issue or VS code issue. Looks like some how PATH got overwritten.

  21. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    To summarize the problem, In the extension we run python using cmd on windows to check if it is a valid python and extract some info about it. In this issue, node was failing to run cmd.exe, because it was not able to find it. This can happen for two reasons: 1) invalid path in ComSpec, 2) system32 got removed from PATH. Both of these can happen when users manually change environment variables or install software that changes environment variables.

  22. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    Thanks for the help.

  23. karthiknadig commented on Dec 9, 2021

    @karthiknadig
    Member

    @cjcocokrisps you can use the environments variable editor in this comment #18138 (comment) . to fix your problem. make sure that system32 is at the top of the list:
    image

  24. cjcocokrisp commented on Dec 9, 2021

    @cjcocokrisp
    Author

    Gotcha thanks again.

  25. locked as resolved and limited conversation to collaborators on Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions