Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 643
krishnab Avatar asked Apr 01 '18 17:04

krishnab


People also ask

How do I activate Anaconda environment in Linux?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .

Should I activate conda environment?

To simply return to the base environment, it's better to call conda activate with no environment specified, rather than to try to deactivate. If you run conda deactivate from your base environment, you may lose the ability to run conda at all. Don't worry, that's local to this shell - you can start a new one.

What is the difference between Anaconda and conda?

Conda is a package manager. It helps you take care of your different packages by handling installing, updating and removing them. Anaconda contains all of the most common packages (tools) a data scientist needs and can be considered the hardware store of data science tools.

What happens with conda activate?

activate . This function creates an instance of the Activator class (defined in the same file) and runs the execute method. The execute method processes the arguments and stores the passed environment name into an instance variable, then decides that the activate command has been passed, so it runs the activate method.


2 Answers

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.

like image 89
sacuL Avatar answered Sep 22 '22 16:09

sacuL


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.

like image 29
taper Avatar answered Sep 23 '22 16:09

taper