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 Interpreter selection not working even though a version is being selected manually #18138

Closed
1 task done
cjcocokrisp opened this issue Dec 8, 2021 · 28 comments
Closed
1 task done
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug

Comments

@cjcocokrisp
Copy link

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
@cjcocokrisp cjcocokrisp added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Dec 8, 2021
@cjcocokrisp
Copy link
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.

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

@cjcocokrisp
Copy link
Author

Is this correct?

image

@karthiknadig
Copy link
Member

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

@cjcocokrisp
Copy link
Author

how do i get that?

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

@brettcannon brettcannon added area-environments Features relating to handling interpreter environments triage and removed triage-needed Needs assignment to the proper sub-team labels Dec 9, 2021
@cjcocokrisp
Copy link
Author

cjcocokrisp commented Dec 9, 2021

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

@karthiknadig
Copy link
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"

@cjcocokrisp
Copy link
Author

image

@karthiknadig
Copy link
Member

Try without the quotes.

@cjcocokrisp
Copy link
Author

image

@karthiknadig
Copy link
Member

@cjcocokrisps can try this with cmd? what does it sat when you run set ComSpec?
image

@cjcocokrisp
Copy link
Author

Nothing was said.
image

@karthiknadig
Copy link
Member

you should just run set ComSpec. Start a new CMD session and run set ComSpec.

@cjcocokrisp
Copy link
Author

image

@karthiknadig
Copy link
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"

@cjcocokrisp
Copy link
Author

Probably input something wrong?

image

@karthiknadig
Copy link
Member

You are missing a \ before .vscode.

@cjcocokrisp
Copy link
Author

image

@karthiknadig
Copy link
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.

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

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

@cjcocokrisp
Copy link
Author

image

@karthiknadig
Copy link
Member

karthiknadig commented Dec 9, 2021

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

@karthiknadig
Copy link
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.

@cjcocokrisp
Copy link
Author

Thanks for the help.

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

@cjcocokrisp
Copy link
Author

Gotcha thanks again.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants