Reputation:
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:
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.
Upvotes: 1
Views: 1702
Reputation: 9923
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",
Upvotes: 1