faq,

Tool - How to change the default Conda Python environment

中文阅读

Problem Description

After installing Conda, open the terminal and activate the base environment by default, as shown below:

However, the base is usually not the environment we need. We have to activate the desired environment (conda activate xxx) every time we enter the terminal, which is particularly cumbersome.

Solution

Linux or Mac OS

Add source activate xxx after conda initialize.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(base) catchzeng:~ catchzeng$ cat .bash_profile
......
# >>> conda initialize >>>
# !! Contents within this block are managed by'conda init' !!
__conda_setup="$('/opt/miniconda3/bin/conda''shell.bash''hook' 2> /dev/null)"
if [$? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [-f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

source activate tensorflow

Note: Normally, conda initialize will be written into .bash_profile when Conda is installed. If you are using zsh, you can find the corresponding one. Here, the default environment name I want is tensorflow, so source activate tensorflow is added here.

Use source command to make the configuration effective.

1
2
(base) catchzeng:~ catchzeng$ source .bash_profile
(tensorflow) catchzeng:~ catchzeng$

Next time, when you open the terminal, the default conda python environment will be tensorflow .

Windows OS

Execute the following command, it will open (if not, it will be created automatically) Profile.

1
(base) PS C:\Users\Administrator> notepad $PROFILE

Add the following commands in Profile.

1
conda activate tensorflow

Next time, when you open the terminal, the default conda python environment will be tensorflow .

1
(tensorflow) PS C:\Users\Administrator>

Reference


CatchZeng
Written by CatchZeng Follow
AI (Machine Learning) and DevOps enthusiast.