如何删除(基地)后,更新终端提示

在升级 miniconda3之后,每当我打开一个终端,它都会在我的用户名和主机前显示“(基础)”。

在这个回答后 https://askubuntu.com/a/1113206/315699建议使用

conda config --set changeps1 False

移除它。

但是这样就不会显示出任何康达环境的迹象了。我想删除它只为基础的一个,以便我可以维护它始终活跃,并有权访问其 Python 和安装的软件包,而不必总是看到这个(基础)占用空间。

111960 次浏览

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.

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

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

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

If you are using zsh, use this instead.

PROMPT=$(echo $PROMPT | 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.

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

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

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

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

If set the auto_activate_base parameter to false, it will instead default to the system environment and avoid the prompt. To do so type:

conda config --set auto_activate_base false


Edited 2021/09/09:

If you are facing the exact same situation as the OP, that you are using conda to manage environments, and wanted to make (base) environment looks no different from the system environment in terminal, check @merv 's answer for the procedures. Note that the prompt string is stored in a certain special variable, depending on the shell you are using, so check the documentation of your shell if it does not work for you.

If you want to use the system environment without conda as the default, my original answer was the solution for you.

Thanks to @merv and @Neinstein for pointing out in the comments.

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

$ conda config --show | grep auto_activate_base
auto_activate_base: True

To set it False

conda config --set auto_activate_base False

and vice-versa.

Note, if changeps1 is kept False, it will hide (env) completely, and in case you want to show (env) only when it's activated, you can set changeps1 to True:

conda config --set changeps1 True

Setting changeps1 to False will hide (env) even if the env is activated and will keep hiding (base) even after auto_activate_base is set to True.

If you are a macOS user and recently faced such issue. here is the solution. Just open terminal then type..

conda deactivate

This solution worked for me. As previously I tried some stuffs with anaconda python.

For me, what worked was:

conda config --set changeps1 false

On my macOS Catalina installation, I just ran conda config --set env_prompt "". That removed it for me.

Simply comment out all lines in ~/.bashrc, except the environment variable:

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

on Debian system, after

conda config --set auto_activate_base false

don't forget in order for effects to take place in the terminal without reloading gnome

bash --login

and verify the status of the flag

conda config --show | grep auto_activate_base

if you are using any distro of Linux this command will work for you,

conda config --set auto_activate_base false

then

conda deactivate

Maybe it will be because of source active

I had this similar issue when I was doing this in flask server and I activated and forgot to deactivate virtual environment.

So go to the folder that virtual environment is active and type

source deactivate

for conda 4.12.0 (under WOS) the following worked (where all the previous answers -these included- didn't do the trick):
in your activate.bat file (mine was at ~/miniconda3/Scripts/activate.bat), change the line:

@REM This may work if there are spaces in anything in %*
@CALL "%~dp0..\condabin\conda.bat" activate %*

into

@REM This may work if there are spaces in anything in %*
@CALL "%~dp0..\condabin\conda.bat" deactivate

this line chage/modification doesn't work in the section (of the activate.bat file):

@if "%_args1_first%"=="+" if NOT "%_args1_last%"=="+" (
@CALL "%~dp0..\condabin\conda.bat" activate
@GOTO :End
)

maybe because it depends on how your miniconda3 (Anaconda Prompt) executable is set up: %windir%\System32\cmd.exe "/K" some-path-to\miniconda3\Scripts\activate.bat some-path-to\miniconda3 (in my case).

caveat: updating conda overwrites this (activate.bat) file; so one has to modify the above line as many times as needed/updated. not much of a deal-breaker if you ask me.