How to set default conda environment so that whenever I open terminal it should get activated instead of base?
Asked Answered
I

3

7

I am using Ubuntu 19.10 and I have installed anaconda. Whenever I open terminal the base environment gets activated by default. I have another environment called kf which I actually use so every time I open terminal I have to conda activate kf. Is there a way so that I can set conda to activate kf environment by default when I open terminal?

Impanel answered 15/11, 2019 at 16:56 Comment(0)
O
8

Conda doesn't have a way to set this, AFAIK, but you can easily accomplish it with some editing of .bashrc (or whatever the initialization file is for your shell). Simply add

conda activate kf

to the bottom of your .bashrc (e.g., echo "conda activate kf" >> ~/.bashrc). Also, you might as well disable the auto-activation of base:

conda config --set auto_activate_base false
Ojeda answered 15/11, 2019 at 22:23 Comment(2)
This solved my problem. The solution is so simple that now I feel dumb for spending two hours searching how to do this.Impanel
Is this file C:\Users\username\.anaconda\navigator\defaults\defaults-2.0.0.ini? C:\Users\username\.anaconda\navigator\anaconda-navigator.ini? How do you find this file for Windows 10 default user installation?Johanson
M
0

Put your conda env name in file like: `.conda-env in root of your project

Edit your ~/.bashrc or ~/.zshrc :

# auto activate conda env
FILE=./.conda-env
if [[ -f "$FILE" ]]; then
    CONDA_ENV=$(<$FILE)
    conda activate $CONDA_ENV
fi
Monsoon answered 19/9, 2022 at 21:42 Comment(0)
V
-1

I found a solution based on this answer from @asmeurer. It's especially useful if you want all the users enter the same env when a new terminal is initiated.

  1. find the anaconda location using which conda, e.g. /usr/local/anaconda3;
  2. mkdir -p /usr/local/anaconda3/etc/conda/activate.d;
  3. put a file named default_env.sh in this folder. the filename is irrelevant; the content of the file is a one-liner: conda activate kf.
Vestavestal answered 21/4, 2023 at 11:4 Comment(1)
This is a wild answer. It is basically recommending that anytime the base environment is activating that it immediately activates a different environment. I would not recommend this. Conda may need to actually activate the base environment to function properly in some circumstances, and this would cryptically prevent that.Ojeda

© 2022 - 2024 — McMap. All rights reserved.