Python Anaconda:我应该在linux中使用`conda activate`还是`source activate`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49600611/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:09:52  来源:igfitidea点击:

Python Anaconda: should I use `conda activate` or `source activate` in linux

pythonanacondaconda

提问by krishnab

So I am used to typing source activate <environment>when starting a python Anaconda environment. That works just fine. But when I create new conda environments I am seeing the message on Ubuntu 16.04 to start the environments with conda activateinstead. Besides the errors about how to set up my shell to use conda activateinstead, I am still not clear on what is the difference between source activate ...and conda activate ...Is there a reason to change? Does anyone know the difference between these two commands? Thanks.

所以我习惯source activate <environment>在启动python Anaconda环境时打字。这工作得很好。但是,当我创建新的 conda 环境时,我在 Ubuntu 16.04 上看到了用于启动环境的消息conda activate。除了关于如何设置我的 shell 以使用的错误之外conda activate,我仍然不清楚source activate ...conda activate ...是否有理由改变之间的区别?有谁知道这两个命令之间的区别?谢谢。

回答by sacuL

As of conda 4.4, conda activateis the preferred way to activate an environment. Generally, you won't find too much of a difference between conda activateand the old source activate, except that it's meant to be faster, and work the same across different operating systems (the latter difference makes conda activatea hugeimprovement IMO).

从 conda 4.4 开始,conda activate是激活环境的首选方式。一般来说,你不会发现conda activate和旧的有太大区别source activate,除了它意味着更快,并且在不同的操作系统上工作相同(后者的差异使IMOconda activate有了巨大的改进)。

From the docs, regarding the release of conda version 4.4.0(released December 2017):

文档中,关于 conda 版本的4.4.0发布(2017 年 12 月发布):

conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You'll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv's activate script.

conda activate:重新设计了环境激活的逻辑和机制。在 conda 4.4 中, conda activate 和 conda terminate 现在是用于激活和停用环境的首选命令。您会发现它们比以前 conda 版本中的 source activate 和 source activate 命令更加快捷。conda activate 命令还具有以下优点:(1) 在所有操作系统、shell 和平台上通用,以及 (2) 不会与来自其他包(如 python virtualenv 的 activate 脚本)的脚本发生路径冲突。

回答by taper

Here is one difference I found. source activatecan be used at the beginning of a bash script to load conda environment, whereas conda activatewould give me an error:

这是我发现的一个区别。source activate可以在 bash 脚本的开头使用来加载 conda 环境,而conda activate会给我一个错误:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

This makes a huge difference to me since I often submit bash jobs to cluster and source activateis the only way to change conda environment.

这对我产生了巨大的影响,因为我经常将 bash 作业提交到集群,并且source activate是更改 conda 环境的唯一方法。

Please correct me if anyone can use conda activatein a bash script.

如果有人可以conda activate在 bash 脚本中使用,请纠正我。

回答by pfRodenas

I am using Anaconda Navigator 1.8.2 with Spyder 3.2.8 on Mac OS, I think is similar to Linux.

我在 Mac OS 上使用 Anaconda Navigator 1.8.2 和 Spyder 3.2.8,我认为类似于 Linux。

It's very easy to install a virtualenv with Anaconda:

使用 Anaconda 安装 virtualenv 非常容易:

Create a new virtualenv

创建一个新的虚拟环境

Select python version

选择python版本

Install packages

安装包

Then install the packages you want

然后安装你想要的包