Tuesday, June 7, 2022

[SOLVED] How to activate conda environment in VSCode on Windows 10

Issue

Whenever I try to activate conda within VSCode on Windows 10, I get a message to initialize the shell.

I tried the following

  • conda init bash and restarting VSCode
  • conda.bat activate -> No change. which python still points to /c/Users/user/anaconda3/python
  • Restarted computer after conda init bash
  • Set the interpreter via F1 > Python:Select Interpreter

I think the problem is within VSCode because I can activate conda from cmd, powershell, gitbash and within the PyCharm terminal.

Do I miss something?

$ conda activate data_science
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

conda info

     active environment : None
       user config file : C:\Users\user\.condarc
 populated config files : 
          conda version : 4.8.3
    conda-build version : 3.18.11
         python version : 3.7.6.final.0
       virtual packages : __cuda=11.0
       base environment : C:\Users\user\anaconda3  (writable)     
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64   
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\user\anaconda3\pkgs
                          C:\Users\user\.conda\pkgs
                          C:\Users\user\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\user\anaconda3\envs
                          C:\Users\user\.conda\envs
                          C:\Users\user\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.8.3 requests/2.22.0 CPython/3.7.6 Windows/10 Windows/10.0.18362
          administrator : False
             netrc file : None
           offline mode : False

Solution

Your '$' indicates to me that you are not actually having a Command Line prompt open, but rather an alternative (probably bash?).

Press Ctrl+Shift+P and search for 'Select default shell', change to Command Line prompt and you should be good to go :)

enter image description here



Answered By - JarroVGIT
Answer Checked By - Candace Johnson (WPSolving Volunteer)