21

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:

  • Added path as shown here
  • As shown here, tried Method 1 and when opening Anaconda Prompt it says:

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

  • Looked at above direction, there is not activate.bat file there.
  • Uninstall and install as shown on metod 2, also did not changed anything.
  • Opened Anaconda Powershell Prompt in addition to 'conda' is not recognized also getting below error:

& : 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.

  • Actually, Path C:\Users\user-name\Anaconda3\shell do not exists when I have looked.

Additional information listed:

  • I have installed MySQL on my PC
  • C:\Users\user-name\Anaconda3\envs is empty
  • Avira antivirus installed
  • Python 3.7.3 installed before Anaconda

What should I do to solve this problem?

questionto42
  • 7,175
  • 4
  • 57
  • 90
isifzade
  • 480
  • 1
  • 5
  • 16
  • 2
    Keep in mind that if you update the path environment variable, that change is not automatically propagated to existing open PowerShell consoles. – Bill_Stewart May 27 '19 at 03:33
  • @Bill_Stewart I did not change evns' path. – isifzade May 27 '19 at 06:11
  • @isifzade In the "Added path as shown here" part you put in, you should have modified your Path variable. Once you have changed this, you will need to close and open all your powershell sessions. Can we assume that you Windows user name is `user-name` or have you actually replaced it with your proper username? (you can run `whoami` on either CMD or powershell to find out your username) – Shadowzee May 27 '19 at 07:03
  • @Shadowzee I have on purpose replaced my original user name with user-name to post a question here. In reality I have used the original user name of PC. – isifzade May 27 '19 at 07:13
  • @isifzade I can't help much more. I found this question via the powershell tag and if the command isn't present, then its either not installed correctly or the path hasn't been added into the environment variables properly. Can you confirm that the directory you added into the environment variables contains the executable "conda"? You might have linked the wrong folder (The linked question says to link Scripts not Shell) – Shadowzee May 27 '19 at 07:19
  • @Shadowzee I did not added the path of shell, It is an error which Powershell prompted. I have added these two into Environment Variables: C:\Users\user-name\Anaconda3\Scripts, C:\Users\user-name\Anaconda3 – isifzade May 27 '19 at 12:39
  • @Bill_Stewart I have just understand what you mean. Even closing the Powershell and restarting PC did not helped. – isifzade May 27 '19 at 12:42

2 Answers2

45

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

Jbbae
  • 824
  • 9
  • 19
4

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.

questionto42
  • 7,175
  • 4
  • 57
  • 90