Issue
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.
Solution
The issue as I reported in my question above appears to have been resolved through the following steps:
- Clean uninstall of VS Code
- Delete virtual environment in my Python coding workspace folder
- Upgrade to Python 3.10.6 from python.org
- Reinstall VS Code (version 1.70.0)
- Install MS Python extension v2022.12.0
- Open workspace folder and save as workspace
- Re-create virtual environment from PS command line in the workspace
Answered By - Gunter Seydack Answer Checked By - Robin (WPSolving Admin)