1

I have set up a virtual environment (.venv) in a VS Code workspace, which I use for learning Python programming, and have selected the Python interpreter in .venv. About 2 out of every 3 times when starting up VS Code, this Python interpreter gets discovered and invoked correctly. Nevertheless, but every so often VS Code seems to have correctly discovered the interpreter and shows a footer message Python 3.10.4('.venv':venv), but then keeps on 'Discovering Python Interpreters', erases the said message, and asks for me to select a Python interpreter. I've linked to a screenshot below, to show how the issue develops. I have appreciated the answers provided in the forum thread 'Visual Studio Code does not detect Virtual Environments', but none of these helps me to solve my problem. Neither has adding the path to the Python executable, located in the .venv, into the default Python interpreter path in settings.json. Has anyone experienced a similar problem and found a solution, please?

Specs:
VS Code: 1.69.2
Windows 10 Pro: 10.0.19044
Python: 3.10.4 MS Python extension: v2022.10.1

VS Code screenshot of Python interpreter selection issue: VS Code screenshot of Python interpreter selection issue

PS: I suspected that the issue might be caused by my workspace folder being located on OneDrive, and thus moved it to my laptop hard disk. This didn't make any difference, and VS Code still behaves in the same erratic manner as described above.

2
  • I use conda to manage my python environments independently of vscode. If you are using it, there is a useful cheat sheet here: docs.conda.io/projects/conda/en/4.6.0/_downloads/…. once the environment is set up in conda it seems to work in vcode without any issues: all the environments appear in the interpreter selector you have already found. I'm sure there is a better way but it works for me. Commented Aug 4, 2022 at 14:19
  • Thanks, @John M, I had a look at the conda manager and might try it someday. To keep things simple for me at this stage, I'm using the Python download from python.org. Commented Aug 4, 2022 at 14:38

1 Answer 1

1

Why is the python interpreter already displayed in the lower right corner but the Discovering Python Interpreters on the left?

Because there may be more than one version of python on the machine, when the python extension finds the version of python you are using ( Show it in the lower right corner ), it will still look for other possible pythons.

The python extension has made improvements to the discovery interpreter:

Previously, the Python extension would try to find Python interpreters every time it activated/loaded. Starting in this release, interpreter discovery is only triggered when a new folder or workspace is opened for the first time, when the “Python: Select Interpreter” command is triggered, and when the interpreters list is refreshed. This leads to much faster load times and startup of features like the language server.

Finally, you can add the following configuration to the settings.json to specify the default interpreter path:

// Just an example path, remember to modify it to suit your path

    "python.defaultInterpreterPath": "C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much, @JialeDu. It was interesting to take note of the improvements made to the discovery interpreter. Regarding the InterpreterPath in settings.json: mine used to look as you suggested. To briefly express it the Linux way: "/pathtoLocal/Programs/Python/Python310/python.exe", which I've changed to the equivalent of: "/pathtoworkspacefolder/.venv/Scripts/python.exe", but that didn't help. As the issue only arises erratically, I suspect it may be caused by my workspace folder being on OneDrive. I'll move it to my laptop hard drive and revert to the forum with the result.