更新 conda 后如何从终端提示中删除(基本) [英] How to remove (base) from terminal prompt after updating conda

查看:33
本文介绍了更新 conda 后如何从终端提示中删除(基本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

conda config --set changeps1 False

删除它.

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

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.

推荐答案

使用 base env 的激活钩子

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

Use the base env's activation hook

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

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

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

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

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

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

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

如果您使用的是 zsh,请改用它.

If you are using zsh, use this instead.

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

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

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

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

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

这篇关于更新 conda 后如何从终端提示中删除(基本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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