6

I am trying to build a basic machine learning algorithm, and to do so I am using the anaconda interpreter for python. However, even though visual studio code appears to have recognized conda as the interpreter, and I have the anaconda3 shell working as a separate application, I cannot get conda to work on vs code. Whenever I try to check for conda, I get the following error:

conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I have tried the fixes linked here: 'Conda' is not recognized as internal or external command

however, they did not work for me. I tried setting conda to my path yet I still got the same error. Thanks in advance!

Spaceball
  • 63
  • 1
  • 1
  • 5
  • Where are you trying to execute that command? – AMC Dec 01 '20 at 02:12
  • @Spaceball -Have you tried restarting VSCode after adding the conda system path? – Jill Cheng Dec 01 '20 at 03:28
  • @AMC I am executing it in powershell in the terminal in vscode, in the path for my project (i.e. C:\Users\User\Documents\Machine-Learning). Is this what you mean? – Spaceball Dec 01 '20 at 06:06
  • @JillCheng I just restarted VSCode and it appears that the issue remains. – Spaceball Dec 01 '20 at 06:17
  • @Spaceball -Could you find the three file locations "Anaconda3", "Anaconda3\Scripts", and "\Library\bin"? And could the conda environment be activated in a powershell terminal outside of VSCode? – Jill Cheng Dec 02 '20 at 01:14
  • @JillCheng - I could find these file locations in my computer. However, when I try to do anything with conda in the outside PowerShell terminal, I also get the same error. – Spaceball Dec 05 '20 at 21:01
  • @Spaceball -The content displayed on the terminal means that the terminal cannot find anaconda. Therefore, if the environment variables are configured correctly, it is recommended that you try to reinstall Anaconda. – Jill Cheng Dec 07 '20 at 01:19
  • It seems like a bug to me if VS Code can locate the anaconda environment in the editor, but when you launch a terminal inside VS Code the environment can't be found. – Robert Sim Jun 13 '21 at 17:05

3 Answers3

18

Try the following:

  1. Run Anaconda/Miniconda
  2. Activate the environment there:
conda activate your-env
  1. Start Visual Studio Code from the Anaconda/Miniconda terminal:
code

enter image description here

Then Visual Studio Code should recognize conda: enter image description here

mentalmushroom
  • 2,261
  • 1
  • 26
  • 34
1

To get python, anaconda, and conda to work well with VS Code I installed the Python extension.

Then in the Python extension settings, set the Python: Conda Path to your conda.exe and the 'Python: Default Interpreter Path to your python.exe.

For me the conda.exe path was in ...\Anaconda3\Library\Scripts\conda.exe and the 'python.exewas the conda base env one at...\Anaconda3\python.exe`

user3731622
  • 4,844
  • 8
  • 45
  • 84
0

Two ways to fix this.

  1. [EASIER] via Anaconda Navigator:

a) If you have Anaconda enviorment already setup. Open Anaconda Navigator --> Home --> Launch VS Code

This must get all python and conda path correctly configured for VS Code editor.

b) To verify, install Python Extentions in VS Code if not yet installed. Then go to Command Pallette --> Prefrences:Open User Settings--> Extentions--> Python

c) then search for Python:default interpreter Path.

enter image description here

and

Python:Conda Path

enter image description here

  1. Via Python Extensions in VS Code Follow b) and c) steps from above 1) approach. Add/Edit both the paths to correct paths on your machine.
Pratap Singh
  • 401
  • 1
  • 4
  • 14