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

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

As of conda 4.4, conda activate is the preferred way to activate an environment. Generally, you wont find too much of a difference between conda activate and the old source activate, except that its 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.

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.

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

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
    wont 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 doesnt 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

Leave a Reply

Your email address will not be published. Required fields are marked *