问题现象
安装完 Conda 之后,开启终端将默认进入 base 环境,如下图所示:

但是,base 经常不是我们所需要的环境。因此,每次进入终端都得 conda activate 到想要的环境,特别繁琐。
解决方法
Linux 或者 Mac 系统
在 conda initialize 后面增加 source activate xxx。
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
注:通常地,
conda initialize在 Conda 安装的时候会被写入.bash_profile,如果你使用的是zsh,可以找到对应的即可。这里,笔者想要的默认环境名称是tensorflow,所以这里添加了source activate tensorflow。
使用 source 命令即可使配置生效。
1 2
(base) catchzeng:~ catchzeng$ source .bash_profile (tensorflow) catchzeng:~ catchzeng$
下次,打开终端默认的 Conda python 环境将会是 tensorflow 。
Windows 系统
执行以下命令,将会打开(如果没有会自动创建)Profile。
1
(base) PS C:\Users\Administrator> notepad $PROFILE
在 Profile 文件中增加如下命令。
1
conda activate tensorflow
下次,打开终端默认的 Conda python 环境将会是 tensorflow 。
1
(tensorflow) PS C:\Users\Administrator>
Service Mesh - Kubernetes LoadBalancer Service External IP pending