42

I have two environments in anaconda, namely: root, 2env. When I open anaconda prompt, I can switch from root to 2env by typing: activate 2env. I also have conda in my powershell, but when I open powershell and try to run conda activate 2env it gives the following error:

CommandNotFoundError: 'activate'

Any suggestions on how to fix this?

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Hector Barbossa
  • 455
  • 1
  • 5
  • 10
  • 1
    Activate is not a valid command for `conda`. Conda is mostly used for package management. Try `conda -h` to see valid commands. You need `activate` in your powershell. – it's-yer-boy-chet Dec 13 '17 at 19:36
  • I also typed `activate env2` but it doesn't activate the env2 environment. – Hector Barbossa Dec 13 '17 at 19:55
  • So the way anaconda works is by default (an option in the install) it doesn't add itself to your `PATH` environmental variable, so the commands will not be available in your shell. Starting the anaconda shell adds the reference to PATH. – it's-yer-boy-chet Dec 13 '17 at 21:03

7 Answers7

65

Although Conda previously did not support PowerShell, this is now resolved in Conda 4.6.

After adding Anaconda3/Scripts/ to your PATH variable, you should be able to initialize Conda for use with powershell with:

conda init powershell

Afterwards, you can use conda normally:

conda activate base
Seanny123
  • 8,776
  • 13
  • 68
  • 124
8

I found this command while using vs code & cmd /k "activate <env> & powershell" . It is working

6

I found this solution:

I've been building on BCSharp's excellent work at my own repo (currently on PR).

Just do: conda install -n root -c pscondaenvs pscondaenvs

You need Conda 4.1 or above (check with conda info conda) - otherwise please install the latest version.

Behavior is exactly like CMD - use activate or deactivate appropriately. It's completely backwards compatible and will also launch both .ps1 and .bat activate.d/deactivate.d scripts.

from https://github.com/conda/conda/issues/626#issuecomment-346224990 has worked really well for me.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
John Forbes
  • 1,248
  • 14
  • 19
1

I have been battling this issue for a while. I found a solution by using a batch script and calling call activate %env%. I hope this can help somebody.

didac
  • 83
  • 1
  • 8
0
  1. Open PowerShell.
  2. Run conda init (not conda init powershell as the accepted answer suggests).
  3. Close and re-open PowerShell.
  4. Use conda normally.
  • Gives `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.` – codeananda Mar 06 '23 at 15:41
0

Someone may encounter some errors, like \WindowsPowerShell\profile.ps1 cannot be loaded because its operation is blocked by software restriction policies Just execution Set-ExecutionPolicy -ExecutionPolicy RemoteSigned as administrator in powershell, after that then reopen powershell the problem should be resolve.

upuil
  • 67
  • 2
  • 8
-5

Here is a work around - start cmd shell . Run - activate . Check - conda env list . Start powershell - powershell .