How to activate different anaconda environment fro

2020-05-20 06:47发布

问题:

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?

回答1:

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


回答2:

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



回答3:

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.



回答4:

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.



回答5:

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