更新conda后如何从终端提示中删除(base) [英] How to remove (base) from terminal prompt after updating 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 建议使用
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的激活钩子
对于每个环境,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) //') "
然后启动一个新的shell不会显示(base)
,并且从嵌套的env中停用也可以解决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后如何从终端提示中删除(base)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!