美文网首页
工具 - 如何修改 Conda 默认启动的 Python 环境

工具 - 如何修改 Conda 默认启动的 Python 环境

作者: CatchZeng | 来源:发表于2021-06-10 10:16 被阅读0次

原文:https://makeoptim.com/tool/conda-default-python-env

问题现象

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

image

但是,base 经常不是我们所需要的环境。因此,每次进入终端都得 conda activate 到想要的环境,特别繁琐。

解决方法

conda initialize 后面增加 source activate xxx

(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 命令即可使配置生效。

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

下次,打开终端默认的 Conda python 环境将会是 tensorflow

参考链接

相关文章

网友评论

      本文标题:工具 - 如何修改 Conda 默认启动的 Python 环境

      本文链接:https://www.haomeiwen.com/subject/hbdueltx.html