mortysporty
mortysporty

Reputation: 2889

Cant activate environment from Visual Studio Code

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?

Upvotes: 5

Views: 17166

Answers (3)

Furin
Furin

Reputation: 582

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.

Upvotes: 9

hzz
hzz

Reputation: 21

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!

Upvotes: 2

Jordan Stefanelli
Jordan Stefanelli

Reputation: 1494

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.

Upvotes: 0

Related Questions