Working with Anaconda in Visual Studio Code

For me, this solution worked in VSC (1.40) ->

1.Set the Interpreter to Python 3.7.1 ('base':conda)

2. Rather than using PowerShell I switched (Select Default Shell) to Command Prompt and started a New Terminal -> now it's in conda (base) environment.

[for Anaconda Distribution, 2018.12]


I beat my head on this for far too long... launching VS Code from an Anaconda Prompt both feels clunky and didn't really work for integrated Powershell terminals (the default VS Code integrated terminal on Windows)

I wanted to be able to launch VS Code from any prompt (and usually the Windows menu shortcut) and still interact with Conda.

These two methods both worked for Anaconda 2020.02, VS Code 1.44.0, on Windows 10.

Easy & Quick

Switch VS Code to use cmd.exe as the default integrated terminal shell by:

  1. opening the command palette (Control-Shift-P)
  2. search for Terminal: Select Default Profile
  3. select Command Prompt

Harder / Powershell

  1. add the location of conda to your PATH (if you did not add it via the installer). For me on an "All Users" install this is C:\ProgramData\Anaconda\Scripts
  2. from an Administrator Powershell prompt change the Powershell Execution Policy to remote signed i.e. Set-ExecutionPolicy RemoteSigned
  3. open an Anaconda Prompt and run conda init powershell which will add Conda related startup to a Powershell profile.ps1 somewhere in your user's profile.

When you run VS Code and either debug a .py or launch a Powershell integrated terminal you should now see a message about "Loading personal and system profiles" and the Conda environment being prefixed on the terminal's prompt.


To set anaconda prompt as your default terminal in VScode:

  1. (type) CTRL + SHIFT + P
  2. (search for:) open settings
  3. (click:) Preferences: Open Settings (JSON)

Then add three line configuration:

{
    ... # any other settings you have already added (remove this line)

    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": ["/K", "C:\\Anaconda3\\Scripts\\activate.bat C:\\Anaconda3"],
    "python.condaPath": "C:\\Anaconda3\\Scripts\\conda.exe"
}

Finally, Restart your VScode