isifzade
isifzade

Reputation: 576

The term 'conda' is not recognized as the name of a cmdlet

I have installed Anaconda 2019.03 for Windows Installer in Windows 10. When typing anything which starts with conda on Powershell getting 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.

I have tried below solutions, which did not solved the problem:

'C:\Users\user-name\Anaconda3\Scripts\activate.bat' is not recognized as an internal or external command, operable program or batch file.

& : The term 'C:\Users\user-name\Anaconda3\shell\condabin\conda-hook.ps1' 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.

Additional information listed:

What should I do to solve this problem?

Upvotes: 26

Views: 83592

Answers (2)

Jbbae
Jbbae

Reputation: 1038

Found an awesome medium post that laid this out cleanly:

  1. Install latest Anaconda + PowerShell
  2. Open Anaconda prompt, and type "conda init powershell"
  3. Open PowerShell and it should work.

Basically creates a file at "%userprofile%\Documents\WindowsPowerShell\profile.ps1" that PowerShell will execute every time it initiates, connecting it to PowerShell.

Source: https://hackf5.medium.com/how-to-enable-anaconda-in-powershell-7-on-windows-394ba62c3f9c

Upvotes: 63

questionto42
questionto42

Reputation: 9638

If you use the default "old" PowerShell 5, check whether the profile.ps1 in C:\Users\USER\Documents\WindowsPowerShell contains:

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "C:\Users\USER\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

enter image description here

If you have a message that the profile.ps1 cannot be executed, solve that problem with set-executionpolicy remotesigned (but: insecure, thus, not recommended!), see:

Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Installieren Sie die neueste PowerShell für neue Funktionen und Verbesserungen! https://aka.ms/PSWindows

. : Die Datei "C:\Users\USER\Documents\WindowsPowerShell\profile.ps1" kann nicht geladen werden, da die Ausführung
von Skripts auf diesem System deaktiviert ist. Weitere Informationen finden Sie unter "about_Execution_Policies"
(https:/go.microsoft.com/fwlink/?LinkID=135170).
In Zeile:1 Zeichen:3
+ . 'C:\Users\USER\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : Sicherheitsfehler: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\WINDOWS\system32> set-executionpolicy remotesigned

Ausführungsrichtlinie ändern
Die Ausführungsrichtlinie trägt zum Schutz vor nicht vertrauenswürdigen Skripts bei. Wenn Sie die Ausführungsrichtlinie
 ändern, sind Sie möglicherweise den im Hilfethema "about_Execution_Policies" unter
"https:/go.microsoft.com/fwlink/?LinkID=135170" beschriebenen Sicherheitsrisiken ausgesetzt. Möchten Sie die
Ausführungsrichtlinie ändern?
[J] Ja  [A] Ja, alle  [N] Nein  [K] Nein, keine  [H] Anhalten  [?] Hilfe (Standard ist "N"): j

enter image description here

After entering j, restart PowerShell. You will see the profile.ps1 in action:

Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Installieren Sie die neueste PowerShell für neue Funktionen und Verbesserungen! https://aka.ms/PSWindows

Das Laden von persönlichen und Systemprofilen dauerte 1400 ms.
(base) PS C:\Users\USER>

enter image description here

In short, try to make it possible that the "profile.ps1" gets loaded. In my case, I did not need this trick anymore since I installed PowerShell 7 which is allowed to load the profile.ps1 by default. You might also just open the old PowerShell 5 from Visual Studio Code instead and change the settings so that conda init runs at the start, see How to add anaconda powershell to vscode?.

Its profile.ps1 had the same content, you find it in C:\Users\USER\Documents\PowerShell\profile.ps1.

When I start PowerShell 7, conda init runs automatically, no insecure tricks needed. Therefore, just install PowerShell 7 in parallel (do not remove the old PowerShell 5!) and use the new version instead.

Upvotes: 6

Related Questions