27

I recently installed Anconda Python on my Linux Mint 19.0 desktop. Actually, I had it installed before and everything worked great, same as with my Mint 19.0 laptop. However, I recently had to wipe my desktop and reinstall everything. Now, whenever I open the Terminal program, the prompt takes several seconds to appear. I've added set -x, set +x to the beginning and end of my bash profile to diagnose where the slowdown is.

The terminal load hangs on this line:

/home/auerilas/anaconda3/bin/conda shell.bash hook

for a few seconds. It's never done this before and doesn't do it on my other computer. Any thoughts on why this is happening? It's not a deal-breaker, but it is annoying.

5
  • 1
    So remove that line? What does it do?
    – Håken Lid
    Oct 8, 2018 at 17:15
  • How do I remove that line? It doesn't appear in .profile or .bashrc
    – Nate
    Oct 9, 2018 at 19:53
  • Try looking in $HOME/.bash_profile. The anaconda installer automatically generates and maintains this line. I am having the same problem: unusually long startup times for Terminal caused by this line.
    – aph
    Oct 9, 2018 at 22:01
  • 1
  • Thanks @aph. On Linux Mint the lines show up in ~/.bashrc. When I comment out those lines, the terminal prompt pops up quickly as expected (of course, anaconda no longer works). That seems to be the source of the issue.
    – Nate
    Oct 10, 2018 at 16:56

5 Answers 5

22

I had the same problem and I solved it by recovering my old .bashrc file then I can load the bash configuration file of Anaconda whenever I need it.

To achieve this , follow these steps

  1. Rename your current .bashrc file to something like conda.bashrc by executing these commands in your terminal
cd ~
mv .bashrc conda.bashrc
mv .bashrc-anaconda3.bak .bashrc
  1. Now, you have to define a custom command in your .bashrc file so it can load Anaconda only when you need it, to do so first you need to open your .bashrc file in a text editor
gedit .bashrc
  1. Add the following lines to end of your .bashrc so it can load the other conda.bashrc file which contain anaconda package configurations
alias anaconda='source  ~/.conda.bashrc'
  1. save .bashrc with the above mentioned edits and type in your terminal window
source .bashrc
  1. now you can load anaconda by simply typing anaconda in your terminal window
anaconda
1
  • 2
    I suggest changing 'mv .bashrc conda.bashrc' to 'cp .bashrc conda.bashrc'. The reason is that before 'mv .bashrc-anaconda3.bak .bashrc' you are momentarily risking to lose .bashrc due to whatever interuptions: loss of power, loss of connection, computer crash, bathroom emergency.. Given that lots of conda users do not have physical or root access to the machine they are running it on, this could lead to days, if not weeks, dealing with the IT department to reset the home folder.
    – Boson Bear
    Feb 25, 2021 at 9:25
20

try making default loading of anaconda to False.

conda config --set auto_activate_base false

this loads path for condo only when you run the command conda activate

1
  • 2
    This is much cleaner.
    – jason m
    Apr 19, 2022 at 0:16
2

An alternative approach, which doesn't involve removing Anaconda, is just to update to a more recent version of Anaconda. This can be done from Anaconda Navigator, and bash startup was greatly improved for me.

2

In my case, caused by Conda as well. I fixed it by commenting out part of ~/.bashrc

Remove/comment this out:

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

Directory might be different depending on where you installed it.

2
  • But it says that this block is managed by conda init, is it an issue if we remove this? In fact I don't understand what this code is doing and do I need to execute it manually when I want to use Conda? Nov 16, 2022 at 15:55
  • It was not an issue for me, but I didn't use Conda a lot so can't say with 100% certainty. This is why you comment stuff out rather than remove it. In case of problems, restore it and keep troubleshooting.
    – naven
    Nov 17, 2022 at 16:03
1

I wrote a simple script that wraps commands related to conda so that conda will only be sourced when you use these commands for the first time, and there's no need to activate conda by hand. This makes my terminal launch like 20 times faster. I use fish by the way, but I'm pretty sure that you can do the same in bash.

function conda-init -d "initialize conda shell functions"
    if type conda | grep -q alias
        echo "initializing conda..."
        eval /Users/madmax/opt/anaconda3/bin/conda "shell.fish" hook $argv | source
    end
end

function python3 -d python3
    conda-init
    functions -e python3
    python3 $argv
end

function py -d python3
    conda-init
    functions -e py
    alias py python3
    python3 $argv
end

function ipy -d ipython
    conda-init
    functions -e ipy
    ipython $argv
    alias ipy ipython
end

alias conda "conda-init; conda"
2
  • do i need to add it to my bash.rc file or do i need to run this script on startup? Nov 12, 2022 at 4:06
  • Thanks! Very necessary. I found Conda was adding 700ms to my shell startup just from the lines conda config --set auto_activate_base false and eval "$('/c/Python/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
    – pyjamas
    Aug 30 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.