Suppose my current activated conda environment is py314 on Linux. When I start a new bash environment from the current one, no matter via command bash, screen, or start vscode from command line, the new bash terminal will set back to base again.

I hope that the conda environment in new bash session should be the same of its parent, so that I don't have to manually change it to the right one every time.

link89's user avatar

It turns out that whenever a new bash environment is started, the .bashrc or .bash_profile will be executed and force conda env to base.

To fix this, I just keep the current CONDA_PREFIX before running conda init procedure, and recovery the environment after the init procedure is done.

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

link89's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.