默认情况下,如何防止 Conda 激活基础环境? [英] How do I prevent Conda from activating the base environment by default?

查看:36
本文介绍了默认情况下,如何防止 Conda 激活基础环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的 Mac 上安装了 anaconda2.默认情况下,Conda 配置为在我打开新的终端会话时激活基本环境.

I recently installed anaconda2 on my Mac. By default Conda is configured to activate the base environment when I open a fresh terminal session.

我想访问 Conda 命令(即,我想将 Conda 的路径添加到我的 $PATH 中,Conda 在初始化时会这样做,这样就可以了).

I want access to the Conda commands (i.e. I want the path to Conda added to my $PATH which Conda does when initialised so that's fine).

不过我一般不会用python编程,也不希望Conda默认激活基础环境.

However I don't ordinarily program in python, and I don't want Conda to activate the base environment by default.

当第一次从提示中执行 conda init 时,Conda 将以下内容添加到我的 .bash_profile 中:

When first executing conda init from the prompt, Conda adds the following to my .bash_profile:

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

如果我注释掉整个块,那么我将无法激活任何 Conda 环境.

If I comment out the whole block, then I can't activate any Conda environments.

我试图注释掉整个块,除了

I tried to comment out the whole block except for

export PATH="/Users/geoff/anaconda2/bin:$PATH"

但是当我开始一个新的会话并试图激活一个环境时,我收到了这个错误信息:

But then when I started a new session and tried to activate an environment, I got this error message:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

这个问题(以及其他喜欢)很有帮助,但最终不能回答我的问题,更适合 linux 用户.

This question (and others like it) are helpful, but doesn't ultimately answer my question and is more suited for linux users.

明确地说,我不是要求从我的 $PS1 中删除 (base) 我是要求 Conda 在我打开一个终端会话.

To be clear, I'm not asking to remove the (base) from my $PS1 I'm asking for Conda not to activate base when I open a terminal session.

推荐答案

我有 conda 4.6,其中包含由 conda 添加的类似代码块.就我而言,有一个 conda 配置设置来禁用自动基本激活:

I have conda 4.6 with a similar block of code that was added by conda. In my case, there's a conda configuration setting to disable the automatic base activation:

conda config --set auto_activate_base false

第一次运行时,它会在您的主目录中创建一个 .condarc 并使用该设置覆盖默认设置.

The first time you run it, it'll create a .condarc in your home directory with that setting to override the default.

这不会使您的 .bash_profile 变得混乱,但它是一种更简洁的解决方案,无需手动编辑 conda 管理的部分.

This wouldn't de-clutter your .bash_profile but it's a cleaner solution without manual editing that section that conda manages.

这篇关于默认情况下,如何防止 Conda 激活基础环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆