Somesh Narwade
Somesh Narwade

Reputation: 336

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

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?

Upvotes: 7

Views: 12165

Answers (3)

Brainor
Brainor

Reputation: 422

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.

Upvotes: -1

Alex Mensak
Alex Mensak

Reputation: 168

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

Upvotes: 0

merv
merv

Reputation: 76950

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

Upvotes: 7

Related Questions