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

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

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

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

来自docs,关于发布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.

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

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

这对我来说意义重大,因为我经常向集群提交 bash 个作业,而 source activate 是更改 conda 环境的唯一方法。

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

我不确定谁会觉得这有用,但是如果

  1. 您的终端由于添加 ">>> conda initialize 而滞后

    " in your .bashrc, then you decide to remove it and add anaconda to the path. If that is the case, then "conda activate env_name" won't work, but "source activate env_name" will work, and then after that, you can use either source activate or conda activate. If you close the shell then to activate the environment again use "source activate env_name"

  2. 仅供参考,从我的 .bashrc 文件中删除“>>> conda initialize >>>” 加速我的终端,它不再滞后,我只是默认 使用“源激活 env_name”
  3. 我有 Ubuntu 20.04,conda 版本:4.10.3,和 conda-build 版本 : 3.21.5