Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell not recognizing conda as cmdlet, function, or operable program

I've been having this issue on my new laptop for a couple of hours and cannot figure out what's causing it. I'm trying to install scikit-learn with conda and 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 install -c anaconda scikit-learn + ~~~~~ + CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Has anybody else had a similar issue on Windows 10?

like image 564
Frontsky Avatar asked Sep 03 '26 07:09

Frontsky


1 Answers

Have you already activated the environment for this use case?

There is a long running thread about this on the GitHub conda discussion regarding conda failures various Windows 7 and higher, here:

https://github.com/conda/conda/issues/626

One suggestion is:

The down and dirty:

  1. Check to see if activate works in cmd.exe.

  2. If doesn't work or not acceptable--as @TurboTim shows:

    Powershell needs the path to each env (anaconda3\envs\someenv\py33.exe. Laborious! :p

    If you don't mind polluting your powershell a little, you can create a profile script which is run every time you open powershell. The below will add the functions Invoke-CmdScript, Conda-Activate, Conda-Deactivate to your powershell. See Tim's link above for why.

    PS C:> New-Item -Path $profile -ItemType File -Force

This creates a script at:

PS C:\> echo $profile

...something like C:\Users\yourUser\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 Edit that script.

PS C:\> explorer $profile

Add this code, save, and reopen powershell (or . $profile ) :

function Invoke-CmdScript {
  param(
    [String] $scriptName
  )
  $cmdLine = """$scriptName"" $args & set"
  & $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
  Select-String '^([^=]*)=(.*)$' | ForEach-Object {
    $varName = $_.Matches[0].Groups[1].Value
    $varValue = $_.Matches[0].Groups[2].Value
    Set-Item Env:$varName $varValue
  }
}
$condaRoot = "$Env:USERPROFILE\Anaconda3"
function Conda-Activate([string]$condaEnv) {Invoke-CmdScript $condaRoot\Scripts\activate.bat $condaEnv}
function Conda-Deactivate {Invoke-CmdScript $condaRoot\Scripts\deactivate.bat}


Usage:
C:\> Conda-Activate TFTheano
C:\> Conda-Activate root
C:\> conda info --envs

Disclaimers: Deactivate, as written, didn't do the job for me, thus I just use Conda-Activate to move around. Also, I don't suspect there are security cautions with adding Invoke-Cmd to profile, so please chime in if 2 cents

like image 103
postanote Avatar answered Sep 05 '26 22:09

postanote



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!