4

I use Python mostly in Spyder for data science. Both Visual Studio Code and virtual environments is fairly new to me.

Anyway, using the terminal in Visual Studio Code I try to switch between environments. I have tried both conda activate venv and activate venv. I get no error message but using conda env list to see which environment is active I seem stuck in Base.

enter image description here

Doing the same thing in the Anaconda Prompt I am allowed to switch between environments.

I use Windows and I start Visual Studio Code from the Anaconda Navigator.

What is going on?

mortysporty
  • 2,749
  • 6
  • 28
  • 51

3 Answers3

8

You need to set your VScode terminal as cmd.exe and not as PowerShell.

#########UPADTE##########

The solution under is deprecated, the new solution can be found in the documentation here:

#########################

Here is how to change your default terminal,

or you can change your settings.json file as follow:

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"

From documentation:

Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell.

Furin
  • 532
  • 10
  • 31
2

When I reinstall the anaconda and run into the same question, that's I can't activate the newly created env that works normally in the cmd, after I try the answer comes before me:

  1. ctrl + shift +p find the settings.json, append two rows: "python.terminal.activateEnvironment": true, "terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe",
  2. choose to run the task in the terminal

it really works, due to my reputation is too low to give credit to the hero, so I write this down. hope it can help you too!

Piotr Labunski
  • 1,638
  • 4
  • 19
  • 26
hzz
  • 21
  • 2
0

Make sure that the admin/elevation of your binaries are consistent.

If VSCode is not elevated, but your environment Python binaries are, they will not be displayed or selectable from VSCode.

That may not be the precise fix for your scenario, but it is very easy to forget if you have many Python versions installed and for example you only use one of them often.

Jordan Stefanelli
  • 1,446
  • 1
  • 13
  • 13