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 not installed" diagnostic despite showing an interpreter in the status bar #11870

Closed
basharatusman opened this issue May 17, 2020 · 20 comments
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority info-needed Issue requires more information from poster regression Bug didn't exist in a previous release

Comments

@basharatusman
Copy link

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.78807
  • OS and version: Catalina 10.15.4
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv

Expected behaviour

Be able to create a folder or workspace for Python projects.

Actual behaviour

Popup error saying that Python is not installed.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

I just started using VSCode. I installed the Python Extension (2020.5.78807). I have python 3.8.0 installed. I can confirm that by running python --version in the terminal in VSCode. The interpreter in the bottom left of the screen shows as 3.8.0. Command pallet shows the same interpreter.

I can create a new file and save it as a .py and it works with no issues. However, if I create a folder or a workspace and then create a file in that, I get a popup saying that Python is not installed (source: Python(Extension).

The code still seems to run ok. I tried uninstalling and reinstalling the extension but no luck. Any thoughts on how I can get rid of this error?

@basharatusman basharatusman added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels May 17, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 19, 2020
@kimadeline
Copy link

Hi @basharatusman, thank you for reaching out.

How did you install python?

create a folder or a workspace and then create a file in that

Do you create the folder from within VS Code?

Can you also copy here the output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)?

Last but not least, can you try installing an older version of the extension (for example 2020.4.76186), 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

Thank you!

@kimadeline kimadeline added the info-needed Issue requires more information from poster label May 19, 2020
@basharatusman
Copy link
Author

basharatusman commented May 19, 2020

@kimadeline thank you for the response.

  • I installed python using Homebrew
  • I normally click open folder on the welcome screen in VSCode. Then navigate to Documents and click create new folder on the bottom left of the directory selection popup and create a new folder. Then I create a .py file in that that folder in VSCode and get the error.
  • I rolled back to 2020.4.76186 on the extension but still getting the error

Here is the output for python. Quick note - I have started using Conda instead of Venv since the original post.

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - control'
User belongs to experiment group 'WebHostNotebook - control'
User belongs to experiment group 'LocalZMQKernel - control'
User belongs to experiment group 'NativeNotebook - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - control'
> conda --version
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Starting Jedi Python language engine.
Diagnostic Code: NoPythonInterpretersDiagnostic, Message: Python is not installed. Please download and install Python before using the extension.
Python interpreter path: /usr/local/anaconda3/bin/python
> conda info --json
> conda info --json
> conda info --json
> conda info --json
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.prefix)"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py site --user-site
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py flake8 --max-line-length=120 "--ignore=F401, F841" --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Documents/VSCode/test2/main.py
cwd: ~/Documents/VSCode/test2
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py flake8 --max-line-length=120 "--ignore=F401, F841" --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Documents/VSCode/test2/main.py
cwd: ~/Documents/VSCode/test2
> conda env list
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/completion.py
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/completion.py
##########Linting Output - flake8##########
> conda env list
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> /usr/local/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2020.5.78807/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version

@kimadeline
Copy link

I couldn't reproduce your issue following the steps you outlined:

folder

It looks like there's some race condition happening though, because the logs you copied show that an interpreter is found:

Diagnostic Code: NoPythonInterpretersDiagnostic, Message: Python is not installed. Please download and install Python before using the extension.
Python interpreter path: /usr/local/anaconda3/bin/python

Can you try rolling back to even older versions of the extension (2020.3.71113, 2020.3.69010, or even 2020.2.64397) so we can pinpoint when this behaviour was introduced?

@basharatusman
Copy link
Author

The issue starts at 2020.3.71113. If i roll back to 2020.3.69010 or earlier then I don't get the error.

@farzad-xgen
Copy link

farzad-xgen commented May 25, 2020

I have the same problem, I couldn't fix it. It makes no harm, you can just dismiss the dialog but it is quite annoying. It happened after I updated to the latest VS Code and selected 'Jedi' as my default engine server.

Version: 1.45.1
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:27:22.494Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.15.0-101-generic

My system:
Ubuntu 18.04.4
python --> Python 2.7
python3 --> Python 3.6.9
python3.8 --> Python 3.8.3

@stevewyl
Copy link

stevewyl commented May 26, 2020

@kimadeline Thanks! Install an older python extension version(2020.4.76186) solved my problem. It seems that the latest python extension has bugs that cannot find a python interpreter even I reset the python path in settings and my project settings.

@kimadeline kimadeline added needs PR important Issue identified as high-priority regression Bug didn't exist in a previous release and removed info-needed Issue requires more information from poster triage labels May 27, 2020
@kimadeline
Copy link

kimadeline commented May 27, 2020

Seems like a race condition in the extension 🤔


Possible solutions (not in any particular order, I personally prefer option 2):

  1. Move the Python interpreter diagnostics (InvalidPythonInterpreterService in diagnostics/checks/pythonInterpreter.ts) to be run after activation
  2. In the Python interpreter diagnostics, replace

const hasInterpreters = await interpreterService.hasInterpreters;

with

let hasInterpreters = await interpreterService.hasInterpreters;
if (!hasInterpreters) {
     hasInterpreters = (await interpreterService.getInterpreters()).length !== 0;
}
  1. Change hasInterpreters directly so that it doesn't return early if the promise hasn't completed, aka change
    return this._hasInterpreters.completed ? this._hasInterpreters.promise : Promise.resolve(false);

to

     return this._hasInterpreters.promise;

⚠️ This change was introduced with the (now defunct) conda run changes because we would call hasInterpreters to check if we found any conda environments, but getInterpreters hadn't been called yet so we'd end up blocked waiting for it to complete (which caused Windows test failures).

  1. Like (3) but special-case when getIntepreters() hasn't been called yet. Add private _hasLooked = false;, set it to true in getInterpreters(), and check it in hasInterpreters:
    if (!this._hasLooked) {
        this.getInterpreters().ignoreErrors(); // Run in the background.
    }
    return this._hasInterpreters.promise;
  1. Instead of hacking around hasInterpreters it would be better if we made the interpreters list observable, which should be done when we refactor interpreter discovery.

@kimadeline kimadeline changed the title Python not installed Python not installed incorrect diagnostic May 27, 2020
@karrtikr karrtikr added the area-environments Features relating to handling interpreter environments label May 27, 2020
@kimadeline kimadeline changed the title Python not installed incorrect diagnostic "Python not installed" incorrect diagnostic May 27, 2020
@kimadeline kimadeline removed their assignment May 27, 2020
@luabud
Copy link
Member

luabud commented Jun 10, 2020

We released a fix for this, but if people are still having issues please do let us know.

@odddemid
Copy link

We released a fix for this, but if people are still having issues please do let us know.

Screen Shot 2020-06-11 at 21 32 43

the problem is still there, I installed python using brew, after that I got this error

@kimadeline
Copy link

kimadeline commented Jun 11, 2020

@odddemid What is the version of the Python extension that's installed?

edit: @odddemid try reloading the window, and if it doesn't work please open a separate issue since it's different from what others in this thread are experiencing (you have the "Select Python Interpreter" message in the status bar, meaning that the extension didn't detect any interpreter at all).

Thank you!

@kimadeline kimadeline changed the title "Python not installed" incorrect diagnostic "Python not installed" diagnostic despite showing an interpreter in the status bar Jun 12, 2020
@odddemid
Copy link

Maybe this will help someone, VSCode did not see the folder "usr/local/bin", I opened the terminal, entered the command "code /" after which the system showed a notification requesting access to the disk, network folders, desktop, etc. I gave full access rights and after that I got a list of possible versions of python.

Unexpected solution to my problem, I don’t understand why VSCode didn’t request access rights when opening it for the first time

Screen Shot 2020-06-16 at 19 53 52

@luabud
Copy link
Member

luabud commented Aug 5, 2020

Closing as fixed. Let us know if you have any issues and we'll reopen.

@luabud luabud closed this as completed Aug 5, 2020
@ghost ghost removed the needs PR label Aug 5, 2020
@dehanjl
Copy link

dehanjl commented Aug 21, 2020

This issue seems to have reappeared with the latest release of the extension. Rolling back to the previous version of the extension seems to fix the issue.

@ZhiJianTan
Copy link

Can confirm that the latest version of the Python extension has this problem. Fixed using @dehan-jl's suggestion.

@karrtikr karrtikr reopened this Aug 24, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Aug 24, 2020
@karthiknadig karthiknadig added the needs spike Label for issues that need investigation before they can be worked on. label Aug 24, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 24, 2020
@karthiknadig karthiknadig added the important Issue identified as high-priority label Aug 24, 2020
@karrtikr
Copy link

@dehan-jl @ZhiJianTan Can you guys please reinstall the latest version of the extension & provide the logs? I'm suspecting to see something similar to #13581.

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Aug 25, 2020
@Soban06
Copy link

Soban06 commented Aug 25, 2020

I stumbled upon the same question.
Here is what I did:

  1. Uninstalled the Python extension.
  2. And then install it again (in my case, I installed the latest version).
  3. Refresh/Restart Visual Studio Code.

@karrtikr
Copy link

@Soban06 Can you please send the information I asked earlier #11870 (comment)?

@ghost ghost removed the needs spike Label for issues that need investigation before they can be worked on. label Sep 24, 2020
@uyw4687
Copy link

uyw4687 commented Dec 25, 2020

#13945 (comment)
This solved the issue for me on Windows.

@sarim
Copy link

sarim commented Jan 2, 2021

Encountered same issue in latest version. Same fix (deleting extension folder and install again) worked. #13945 (comment)

@nina-mir
Copy link

Hi @basharatusman, thank you for reaching out.

How did you install python?

create a folder or a workspace and then create a file in that

Do you create the folder from within VS Code?

Can you also copy here the output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)?

Last but not least, can you try installing an older version of the extension (for example 2020.4.76186), 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

Thank you!

@kimadeline I came here from 9576. I was having the same problem as folks on that issue. So, I tried your suggestion of installing an older version of Microsoft Python extension and yay! VScode not only recognizes my globally installed python, but also any of my virtual env versions with no problem.

Thank you!

My OS is Ubuntu 20.04 LTS and I remember updating my OS with some vscode upgrades very, very recently. Basically, going back about a month back in terms of the Microsoft python extension's version allows python to be recognized by vscode.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
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 important Issue identified as high-priority info-needed Issue requires more information from poster regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests