128

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.

Homero Esmeraldo
  • 1,864
  • 2
  • 18
  • 34

12 Answers12

200

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.

Bryan P
  • 5,900
  • 5
  • 34
  • 49
Yokissa
  • 2,155
  • 2
  • 6
  • 5
  • 7
    The issue in OP is that they don't want the PS1 change even when **base** is activated. – merv Sep 10 '19 at 03:02
  • 11
    this is what I was looking for. – ether_joe Nov 13 '19 at 01:39
  • 1
    `[[ $PS1 =~ ^\(base\) ]] && conda config --set auto_activate_base false` persistent between (re)installations. (Add it into `~/.bashrc`, after Conda's section) – ceremcem Dec 14 '20 at 10:38
  • @merv you can do that by running this: `conda config --set changeps1 false` – Zaki Aziz Apr 17 '21 at 16:54
  • @ZakiAziz that affects all environments. OP only wants **base** environment not to change PS1, other envs should still change it. Many people seem to end up on this question, when really they want to [prevent **base** auto-activation](https://stackoverflow.com/q/54429210/570918) or [prevent editing PS1](https://stackoverflow.com/q/36499220/570918). – merv Apr 17 '21 at 19:31
  • 10
    **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. – Neinstein Jun 24 '21 at 08:09
  • @Neinstein You are right in saying that this is not the correct answer to the OP's question. I was not aware that conda was used to manage environments when I answered this question and it was my intention to go back to use the system environment when my search end up at this question, so I left my solution here. I will edit the answer accordingly. – Yokissa Sep 09 '21 at 02:02
96

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.

cnu
  • 36,135
  • 23
  • 65
  • 63
merv
  • 67,214
  • 13
  • 180
  • 245
  • Doesn't work for me (conda 4.8.3; Python 3.8.3). I have still the same "(base)" in my shell. – Awaaaaarghhh Oct 05 '20 at 11:39
  • @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 Oct 07 '20 at 04:59
  • @merv probably one just need to reboot the PC after executing your commands. - Just restarting the shell didn't help. – Awaaaaarghhh Oct 07 '20 at 20:56
  • There is an extra space at the end. OTOH there is no need to add the double quotes in this kind of bash assignments. – memeplex Nov 14 '20 at 02:13
  • 1
    This worked for me. My installation directory ended up being `~/opt/anaconda3/etc/conda/activate.d/remove_base_ps1.sh`. Took me some time to understand where the shell script should go – Asif Oct 05 '22 at 05:09
  • 1
    all I did for zsh that works for me was to add `PROMPT=$(echo $PROMPT | sed 's/(base) //')` right after conda initialize script at `~/.zshrc`. thanks for the advise btw. – Matheus Camara Oct 24 '22 at 15:14
29

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.

monti
  • 734
  • 8
  • 16
  • 3
    What does this add that is not already in [this other early answer](https://stackoverflow.com/a/57642532/570918)? – merv Jun 28 '20 at 06:41
  • 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 – Ed Griebel Sep 19 '20 at 04:19
  • 1
    @merv: although the solution is the same, there is more explanation of how the different settings work, so could be helpful for some readers – Bryan P Nov 19 '22 at 16:10
15

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

conda config --set auto_activate_base false

then

conda deactivate
user438383
  • 5,716
  • 8
  • 28
  • 43
Manishyadav
  • 1,361
  • 1
  • 8
  • 26
12

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

PS1=$(echo $PS1 | sed 's/(base)//')
ewindes
  • 790
  • 7
  • 17
  • 5
    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. – David Apr 22 '19 at 23:06
5

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.

codexaxor
  • 97
  • 2
  • 5
  • this is same for linux also....conda deactivate to remove base env....conda activate to add base env.... – sifar Aug 18 '22 at 10:11
4

For me, what worked was:

conda config --set changeps1 false 
Cecília Assis
  • 139
  • 1
  • 10
  • 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](https://stackoverflow.com/questions/36499220/anaconda-disable-prompt-change). – merv Apr 17 '21 at 19:38
3

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

Artem Kozlenkov
  • 975
  • 9
  • 11
2

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
1

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.

Manuel F
  • 145
  • 2
  • 7
0

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 <<<
Timin
  • 25
  • 1
  • 1
    You should make sure you know what is the consequence of commenting these lines apart from removing "base" from the shell label. – Homero Esmeraldo Sep 07 '20 at 15:34
  • **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). – merv Nov 11 '20 at 16:06
  • 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 – water stone Mar 16 '22 at 17:48
-1

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

Matt
  • 2,576
  • 6
  • 34
  • 52
  • 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. – merv Sep 02 '20 at 17:44