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?
How to set default conda environment so that whenever I open terminal it should get activated instead of base?
Asked Answered
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
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
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
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.
- find the anaconda location using
which conda
, e.g./usr/local/anaconda3
; mkdir -p /usr/local/anaconda3/etc/conda/activate.d
;- 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
.
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.