65

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 activate instead. Besides the errors about how to set up my shell to use conda activate instead, 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.

0

3 Answers 3

86

As of conda 4.4, conda activate is the preferred way to activate an environment. Generally, you won't find too much of a difference between conda activate and 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 activate a huge improvement IMO).

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

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.

5
  • 1
    Ahh, I see. I did not see this section in the documentation, so thanks for pointing it out. I see the difference now. Drat, now I have to go and update my zsh config and bash config, and .... :).
    – krishnab
    Apr 1, 2018 at 17:55
  • 1
    Yeah... someone should really update the rest of the documentation, because the only info I found (what I posted above) is hidden away in the release notes...
    – sacuL
    Apr 1, 2018 at 17:57
  • Haha, there is so much Anaconda documentation out there now, I imagine even the Continuum folks have a hard time knowing where to update stuff after each change :). But I guess it is the same way all around. I was installing Tensorflow-gpu the other day and that documentation is even worse--because the package installs are very tightly linked to the cuda versions and such. That was a pain. At least the Anaconda error message tells me what to do :).
    – krishnab
    Apr 1, 2018 at 18:01
  • 1
    the problem with conda activate is that it assumes that conda is already in your PATH; source activate was typically how I put conda in my PATH in the first place. Feb 19, 2019 at 14:01
  • 1
    Conda release notes are now at docs.conda.io/projects/conda/en/latest/release-notes.html -- scroll down to the release notes for Conda 4.4.0 to read about "conda activate vs source activate". Aug 31, 2019 at 16:16
17

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

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 activate is the only way to change conda environment.

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

4
  • 9
    See this link: github.com/conda/conda/issues/7980. These two lines of code at the beginning of your bash script will allow you to use conda activate in a script: CONDA_BASE=$(conda info --base) ; source $CONDA_BASE/etc/profile.d/conda.sh
    – Luigi
    Jul 25, 2019 at 16:24
  • 4
    what about in a docker file?
    – John
    Jul 29, 2020 at 13:16
  • For use in Dockerfile try this
    – Rm4n
    Sep 22, 2022 at 6:56
  • Thank you @Luigi ... solved an age-old problem Jul 8 at 3:41
0

I am not sure who might find this useful, but if

  1. Your terminal lags due to the addition ">>> 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. FYI, removing ">>> conda initialize >>>" from my .bashrc file has speedup my terminal and it doesn't lag anymore and I just default in using "source activate env_name"
  3. I have Ubuntu 20.04, conda version : 4.10.3, and conda-build version : 3.21.5

Your Answer

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.