Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Conda from activating the base environment by default?

Tags:

bash

conda

I recently installed anaconda2 on my Mac. By default Conda is configured to activate the base environment when I open a fresh terminal session.

I want access to the Conda commands (i.e. I want the path to Conda added to my $PATH which Conda does when initialised so that's fine).

However I don't ordinarily program in python, and I don't want Conda to activate the base environment by default.

When first executing conda init from the prompt, Conda adds the following to my .bash_profile:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/geoff/anaconda2/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
if [ -f "/Users/geoff/anaconda2/etc/profile.d/conda.sh" ]; then
    . "/Users/geoff/anaconda2/etc/profile.d/conda.sh"
else
    export PATH="/Users/geoff/anaconda2/bin:$PATH"
fi
# fi
unset __conda_setup
# <<< conda initialize <<<

If I comment out the whole block, then I can't activate any Conda environments.

I tried to comment out the whole block except for

export PATH="/Users/geoff/anaconda2/bin:$PATH"

But then when I started a new session and tried to activate an environment, I got this error message:

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

This question (and others like it) are helpful, but doesn't ultimately answer my question and is more suited for linux users.

To be clear, I'm not asking to remove the (base) from my $PS1 I'm asking for Conda not to activate base when I open a terminal session.

like image 399
DryLabRebel Avatar asked Jan 29 '19 20:01

DryLabRebel


People also ask

How do you stop conda from activating base Vscode?

You can set "python. terminal. activateEnvironment": false in your settings to deactivate activation of your environment.

Can I remove conda base environment?

It's not that, but instead that you can't remove the base environment, which is what the --all flag does. You can't uninstall all packages in base because that's where the conda executable lives. Instead, what you want to do is uninstall all user-installed packages.

What is conda activate base?

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.


Video Answer


4 Answers

There're 3 ways to achieve this after conda 4.6. (The last method has the highest priority.)

  1. Use sub-command conda config to change the setting.

    conda config --set auto_activate_base false
    
  2. In fact, the former conda config sub-command is changing configuration file .condarc. We can modify .condarc directly. Add following content into .condarc under your home directory,

    # auto_activate_base (bool)
    #   Automatically activate the base environment during shell
    #   initialization. for `conda init`
    auto_activate_base: false
    
  3. Set environment variable CONDA_AUTO_ACTIVATE_BASE in the shell's init file. (.bashrc for bash, .zshrc for zsh)

    export CONDA_AUTO_ACTIVATE_BASE=false
    

    To convert from the condarc file-based configuration parameter name to the environment variable parameter name, make the name all uppercase and prepend CONDA_. For example, conda’s always_yes configuration parameter can be specified using a CONDA_ALWAYS_YES environment variable.

    The environment settings take precedence over corresponding settings in .condarc file.

References

  • The Conda Configuration Engine for Power Users
  • Using the .condarc conda configuration file
  • conda config --describe
  • Conda 4.6 Release
like image 31
Simba Avatar answered Oct 18 '22 04:10

Simba


I have conda 4.6 with a similar block of code that was added by conda. In my case, there's a conda configuration setting to disable the automatic base activation:

conda config --set auto_activate_base false

The first time you run it, it'll create a .condarc in your home directory with that setting to override the default.

This wouldn't de-clutter your .bash_profile but it's a cleaner solution without manual editing that section that conda manages.

like image 196
jieong Avatar answered Oct 18 '22 05:10

jieong


The answer depends a little bit on the version of conda that you have installed. For versions of conda >= 4.4, it should be enough to deactivate the conda environment after the initialization, so add

conda deactivate

right underneath

# <<< conda initialize <<<
like image 41
darthbith Avatar answered Oct 18 '22 05:10

darthbith


To disable auto activation of conda base environment in terminal:

conda config --set auto_activate_base false

To activate conda base environment:

conda activate
like image 32
kurianmat Avatar answered Oct 18 '22 06:10

kurianmat