0

On Windows.

Normally, when I run

python -m venv myvenv

In the bottom right corner, VSCODE will detect this virtual environment and prompt me to set it as default interpreter.

In fact, this was working up to about 30 minutes ago.

However, I was having errors with path in Git Bash and followed instructions here to change my default terminal back to the CMD.

After doing so, VSCODE no longer recognizes any virtual environment I create automatically. Doing CTRL SHIFT P and trying to set it manually doesn't work either, as it cannot seem to find it.

However, if I do

source myvenv/Scripts/activate

It does indeed open the virtual environment. However, this only lasts for that one terminal session.

How can I fix this problem?

AndW
  • 726
  • 6
  • 31
  • `trying to set it manually doesn't work either, as it cannot seem to find it.` Do you mean that you can't select `python.exe` when you turn to the folder `myvenv/Scripts/`? – Molly Wang-MSFT May 17 '21 at 03:48

2 Answers2

0

Try the solution from the below link and do let me know in the comments if that works for you

Even though I have referred to the exact section of the page required for your resolution, as suggested by @Ch3steR, I am putting the required details below :-

From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):

No interpreter selected

The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you don't see the desired interpreter, configure your Python environment.

for setting python environment, please follow below instructions: -

To select a specific environment, use the Python: Select Interpreter command from the Command Palette (⇧⌘P).

Python: Select Interpreter command

You can switch environments at any time; switching environments helps you test different parts of your project with different interpreters or library versions as needed.

The Python: Select Interpreter command displays a list of available global environments, conda environments, and virtual environments.

Note: When using an Anaconda distribution, the correct interpreter should have the suffix ('base':conda), for example Python 3.7.3 64-bit ('base':conda).

Selecting an interpreter sets the python.pythonPath value in your workspace settings to the path of the interpreter. To see the setting, select File > Preferences > Settings (Code > Preferences > Settings on macOS), then select the Workspace Settings tab.

Reference :-

https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter

https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

Thanks

Pratap Alok Raj
  • 1,098
  • 10
  • 19
  • That comment was auto-generated from [From Review](https://stackoverflow.com/review/low-quality-posts/28977852). I didn't downvote. I appreciate that you improved your answer. All can I do is upvote. – Ch3steR May 15 '21 at 07:21
0

The crisp of VS code Environment setting as per there site:

From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too) The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you don't see the desired interpreter, see https://code.visualstudio.com/docs/python/environments

Note: When using an Anaconda distribution, the correct interpreter should have the suffix ('base':conda), for example Python 3.7.3 64-bit ('base':conda).

Selecting an interpreter sets the python.pythonPath value in your workspace settings to the path of the interpreter. To see the setting, select File > Preferences > Settings (Code > Preferences > Settings on macOS), then select the Workspace Settings tab.

Note: If you select an interpreter without a workspace folder open, VS Code sets python.pythonPath in your user settings instead, which sets the default interpreter for VS Code in general. The user setting makes sure you always have a default interpreter for Python projects. The workspace settings let you override the user setting.

Above Paragraph is taken from: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter

Anant Arun
  • 95
  • 7