Python 如何从powershell激活不同的anaconda环境
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47800794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to activate different anaconda environment from powershell
提问by Hector Barbossa
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:
我在 anaconda 中有两个环境,即:root
, 2env
. 当我打开 anaconda 提示符时,我可以通过键入从root
到切换2env
:activate 2env
。我的 powershell 中也有 conda,但是当我打开 powershell 并尝试运行conda activate 2env
它时,会出现以下错误:
CommandNotFoundError: 'activate'
CommandNotFoundError: '激活'
Any suggestions on how to fix this?
对于如何解决这个问题,有任何的建议吗?
回答by Seanny123
Although Conda previously did not support PowerShell, this is now resolved in Conda 4.6.
尽管 Conda 以前不支持 PowerShell,但现在在Conda 4.6 中解决了这个问题。
After adding Anaconda3/Scripts/
to your PATH variable, you should be able to initialize Conda for use with powershell with:
添加Anaconda3/Scripts/
到您的 PATH 变量后,您应该能够初始化 Conda 以与 powershell 一起使用:
conda init powershell
Afterwards, you can use conda
normally:
之后就可以conda
正常使用了:
conda activate base
回答by Hector Barbossa
I found this command while using vs code & cmd /k "activate <env> & powershell"
.
It is working
我在使用 vs code 时发现了这个命令& cmd /k "activate <env> & powershell"
。这是工作
回答by John Forbes
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.
我一直在我自己的 repo(目前在 PR 上)建立 BCSharp 的出色工作。
做就是了:
conda install -n root -c pscondaenvs pscondaenvs
您需要 Conda 4.1 或更高版本(检查 conda info conda) - 否则请安装最新版本。
行为与 CMD 完全一样 - 适当地使用激活或停用。它完全向后兼容,还将启动 .ps1 和 .bat activate.d/deactivate.d 脚本。
from https://github.com/conda/conda/issues/626#issuecomment-346224990has worked really well for me.
来自https://github.com/conda/conda/issues/626#issuecomment-346224990对我来说效果很好。
回答by didac
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.
我一直在与这个问题作斗争。我通过使用批处理脚本并调用call activate %env%
. 我希望这可以帮助某人。
回答by whatdhack
Here is a work around - start cmd shell . Run - activate . Check - conda env list . Start powershell - powershell .
这是一个变通方法 - 启动 cmd shell。运行-激活。检查 conda 环境列表。启动 powershell-powershell。