bash 更新 conda 后如何从终端提示中删除(基本)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55171696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:06:22  来源:igfitidea点击:

How to remove (base) from terminal prompt after updating conda

bashterminalanacondacondaminiconda

提问by Homero Esmeraldo

After updating miniconda3, whenever I open a terminal it shows "(base)" in front of my username and host.

更新 miniconda3 后,每当我打开终端时,它都会在我的用户名和主机前面显示“(base)”。

In this answer post https://askubuntu.com/a/1113206/315699it was suggested to use

在这个回答帖子https://askubuntu.com/a/1113206/315699 中,建议使用

conda config --set changeps1 False

To remove it.

要删除它。

But that would remove the indication for any conda environment. I would like to remove it only for the base one, so that I can maintain it always active and have access to its python and installed packages without having to always see this (base) taking up space.

但这将消除任何 conda 环境的指示。我想只为基础版本删除它,以便我可以保持它始终处于活动状态并可以访问其 python 和已安装的软件包,而不必总是看到这个(基础)占用空间。

回答by merv

Use the baseenv's activation hook

使用baseenv 的激活钩子

For each env, any scripts in the etc/conda/activate.ddirectory will be executed post-activation (likewise etc/conda/deactivate.dscripts for deactivation). If you add a script to remove the (base), similar to @ewindes suggestion, you'll get the behavior you desire.

对于每个 env,etc/conda/activate.d目录中的任何脚本都将在激活后执行(同样etc/conda/deactivate.d用于停用的脚本)。如果您添加一个脚本来删除(base),类似于@ewindes 建议,您将获得所需的行为。

I had to create this directory for base, which is just the root of your Anaconda/Miniconda folder. E.g.,

我必须为base创建这个目录,它只是你的 Anaconda/Miniconda 文件夹的根目录。例如,

mkdir -p miniconda3/etc/conda/activate.d

Then made a simple file in there (e.g., remove_base_ps1.sh) with one line:

然后在其中创建一个简单的文件(例如,remove_base_ps1.sh),其中包含一行:

PS1="$(echo "$PS1" | sed 's/(base) //') "

Launching a new shell then does not show (base), and deactivating out of nested envs also takes care of the PS1 change.

启动一个新的 shell 然后不显示(base),并且从嵌套的 envs 中停用也会处理 PS1 的变化。

Note: You must add quotes around $PS1 if you want to preserve ending spaces.

注意:如果要保留结尾空格,则必须在 $PS1 周围添加引号。

回答by Yokissa

That's because conda's base environment is activated on startup.

那是因为 conda 的基础环境在启动时被激活。

To set the auto_activate_base parameter to false, type:

要将 auto_activate_base 参数设置为 false,请键入:

conda config --set auto_activate_base false

conda config --set auto_activate_base false

回答by ewindes

You could add a command to your .bashrc to remove the "(base)" string from PS1:

您可以向 .bashrc 添加命令以从 PS1 中删除“(基本)”字符串:

PS1=$(echo $PS1 | sed 's/(base)//')

回答by Kanish

If you are using Mac just HardResetthe terminal. Open Terminal > Shell > Hard Reset

如果您使用的是 Mac,只需HardReset终端。打开终端>外壳>硬重置

It works for me.

这个对我有用。

回答by Ivan Calderon

Update 2020 from github repo SmirkCao:

从 github repo SmirkCao更新 2020 :

conda config --set changeps1 false

回答by monti

By default, auto_activate_base is set to True when installing anaconda. To check this, run:

默认情况下,安装 anaconda 时 auto_activate_base 设置为 True。要检查这一点,请运行:

conda config --show | grep auto_activate_base

outputs >>> auto_activate_base: True

输出 >>> auto_activate_base: True

To set it false

将其设置为假

conda config --set auto_activate_base False

and vice-versa

反之亦然

回答by Khyar Ali

When using conda and vscode. conda activates the virtual environment in your project if you have one and if not conda and vscode create one for you called base.

使用 conda 和 vscode 时。如果你有一个,conda 会激活你项目中的虚拟环境,如果没有 conda 和 vscode 为你创建一个叫做 base 的虚拟环境。

to deactivate it, use:

要停用它,请使用:

conda deactivate