ChatGPT解决这个技术问题 Extra ChatGPT

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

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

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

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.


Y
Yokissa

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

To set the auto_activate_base parameter to false, 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 to 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 and not using conda at all, my original answer was the solution for you.

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


The issue in OP is that they don't want the PS1 change even when base is activated.
this is what I was looking for.
[[ $PS1 =~ ^\(base\) ]] && conda config --set auto_activate_base false persistent between (re)installations. (Add it into ~/.bashrc, after Conda's section)
@merv you can do that by running this: conda config --set changeps1 false
This does not make the (base) prefix hidden for the base environment, this makes the base environment not activate at all. The shell will use the system Python, not the Anaconda one! This is not what OP wants at all, and it will cause a lot of problem for inexperienced users. If you do a conda activate, the (base) conda prefix will appear, as you actually load it. The fact this answer has 98+ upvotes show how harmful it is - 98 people thought they solved this problem, while they didn't.
c
cnu

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.


Doesn't work for me (conda 4.8.3; Python 3.8.3). I have still the same "(base)" in my shell.
@Awaaaaarghhh ask a new question with details on how it failed and I'll have a look. Include the output of conda info in the question.
@merv probably one just need to reboot the PC after executing your commands. - Just restarting the shell didn't help.
There is an extra space at the end. OTOH there is no need to add the double quotes in this kind of bash assignments.
J
Jovial Joe Jayarson

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.


What does this add that is not already in this other early answer?
This is the one that worked for me in zsh with OhMyZsh on macOS Catalina (10.15) when the accepted answer didn't, probably because prompts are done slightly differently than bash
e
ewindes

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

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

Your answer adds a space at the beginning of PS1 and removes a space after $, so the text looks like: _rosgori@sa6:~$cd Documents/. This line improves that: PS1="$(echo $PS1 | sed 's/(base) //') ", unfortunately, when you activate another env, then deactivate, the (base) will be there.
c
codexaxor

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.


C
Cecília Assis

For me, what worked was:

conda config --set changeps1 false 

But how do you get this to only prevent it for base and no other environment? That is OP's question. This is instead answering this question.
A
Artem Kozlenkov

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


M
Manishyadav

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

conda config --set auto_activate_base false

than

conda deactivate

it worked, but is also important to have run conda config --set auto_activate_base false
okk i'll keep this in mind!!
M
Manuel F

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.


T
Timin

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 <<<

You should make sure you know what is the consequence of commenting these lines apart from removing "base" from the shell label.
I strongly recommend against this. Those double exclamation warnings are there to indicate that you shouldn't edit this region. Plus, this removes all the newer Conda v4.4+ shell functionality and leaves only the pre-v4.4 PATH management which the devs only include as an absolute baseline fallback (e.g., for unsupported shells only).
there is nothing wrong commenting out or simply removing those lines, you can also choose not to let conda to add those lines to your .bashrc. as long as you set the PATH etc env variables to your preference, there is no need for these lines to exist
B
Binwin Viju LatentView

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

K
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.

to deactivate it, use:

conda deactivate

M
Matt

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


That removes it for everything - please reread the OP (only wants change for base). Even if this was what was desired, changeps1 would be more effective; this solution still results in running code to manage PS1 even though it only ever inserts empty strings.