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

How can I get Pylance to "assume" the version of Python I am running? #22191

Closed
philosofool opened this issue Oct 10, 2023 · 4 comments
Closed
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@philosofool
Copy link

The Python Langauge Server Output in VSCode reports "Assuming Python 3.8" but I would like it to detect the current version of Python or, at least, be configured to run with the version of Python that I am using.
Sample Output:

2023-10-10 17:03:44.967 [info] [Info  - 5:03:44 PM] (112106) Pylance language server 2023.10.10 (pyright 45942a15) starting
2023-10-10 17:03:44.967 [info] [Info  - 5:03:44 PM] (112106) Server root directory: /home/jovyan/.vscode-server/extensions/ms-python.vscode-pylance-2023.10.10/dist
2023-10-10 17:03:44.968 [info] [Info  - 5:03:44 PM] (112106) Starting service instance "code"
2023-10-10 17:03:44.973 [info] [Info  - 5:03:44 PM] (112106) Auto format for strings enabled
2023-10-10 17:03:45.013 [info] [Info  - 5:03:45 PM] (112106) Setting pythonPath for service "code": "/bin/python3"
2023-10-10 17:03:45.013 [info] [Info  - 5:03:45 PM] (112106) Setting environmentName for service "code": "3.8.10 (global)"
2023-10-10 17:03:45.023 [info] [Warn  - 5:03:45 PM] (112106) stubPath /code/typings is not a valid directory.
2023-10-10 17:03:45.044 [info] [Info  - 5:03:45 PM] (112106) Assuming Python version 3.8
2023-10-10 17:03:45.829 [info] [Info  - 5:03:45 PM] (112106) Found 388 source files

From terminal, python --version outputs python 3.9.10. However, Pylance language server is "assuming Python 3.8" according to the Python Language Server output. I believe this is the cause of a Pylance false positive when type hinting with indexed classes, e.g. def flatten(list[list]): I get an error Subscript for class "list" will generate runtime exception; enclose type annotation in quotes (Perhaps this isn't really a false positive, if it's using Python 3.8, which did not support that typing syntax, but I think you see my point.)

@philosofool
Copy link
Author

Possibly, this is because I am Attaching VSCode to a Docker container. However, I would like the language server to attach to the same container as the terminal, please.

@debonte
Copy link

debonte commented Oct 10, 2023

Transferring to vscode-python since they own Python environment selection and tell us which environment/version is in use.

@debonte debonte transferred this issue from microsoft/pylance-release Oct 10, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Oct 10, 2023
@karthiknadig
Copy link
Member

@philosofool Can you share the Output > Python logs? it should say which one is selected. If you enable debug or trace level logging, it will show what python extension assumes the version is.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Oct 10, 2023
@philosofool
Copy link
Author

@philosofool Can you share the Output > Python logs? it should say which one is selected. If you enable debug or trace level logging, it will show what python extension assumes the version is.

My partner used to say "you don't need to help me open the jar, the jar just needs to hear me ask you for help, and then it opens." It turns out I just needed to select the correct Python interpreter (Ctrl+Shft+P > Select Python Interpreter) and Pylance parsed the code using the selected version of Python. Thanks for your attention.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Oct 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants