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?

3
  • 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. Dec 13, 2017 at 19:36
  • I also typed activate env2 but it doesn't activate the env2 environment. Dec 13, 2017 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. Dec 13, 2017 at 21:03

7 Answers 7

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
5
  • 1
    It cannot activate the virtualenv.
    – GoingMyWay
    May 7, 2019 at 13:34
  • @GoingMyWay Conda 4.6.14 is functional
    – jCisco
    Jun 5, 2019 at 12:21
  • If for some reason you are using a custom prompt (for something else), it gets messed up by the activate. But you can fix it, if you're good at PS profile hacking and adding: if ("$env:CONDA_PROMPT_MODIFIER" -match "(base)") { ... }.
    – not2qubit
    Apr 23, 2020 at 17:06
  • @not2qubit I think that would be a valid question-answer pair which you could link to
    – Seanny123
    Apr 23, 2020 at 18:10
  • Does conda init powershell need to be run from powershell, or can it be run from a command prompt? Apr 8, 2021 at 0:11
8

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

1
  • it opens in powershell but you can change envs making it useless for my usecase.
    – Umar.H
    Jan 17, 2021 at 20:38
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.

1
  • 1
    This no longer works with Conda 4.6, which resolves issue #626.
    – Seanny123
    Feb 21, 2019 at 15:53
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.

0
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.
1
  • 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 6 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.

-5

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.