Search code examples
pythonmacosanacondaconda

Cannot run conda in terminal on MacOS


I have problems running the conda command in a terminal window on MacOS. I know I am not alone, because I have researched many answers to this question, yet still cannot solve it. Here is what I did specifically.

I downloaded Anaconda3 2019.10 for macOS (Python 3.7 version, 64-Bit Graphical Installer (654 MB)) from here: https://www.anaconda.com/distribution/ and installed it using all default settings.

I opened a terminal window on my mac to run conda --version. Then it says: conda: Command not found.

I have read various posts saying that you need to modify your ~/.bash_profile, so I open ~/.bash_profile and it looks like this:

 # added by Anaconda3 2019.10 installer
 # >>> conda init >>>
 # !! Contents within this block are managed by 'conda init' !!
 __conda_setup="$(CONDA_REPORT_ERRORS=false '/opt/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
 if [ $? -eq 0 ]; then
     \eval "$__conda_setup"
 else
     if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
         . "/opt/anaconda3/etc/profile.d/conda.sh"
         CONDA_CHANGEPS1=false conda activate base
     else
         \export PATH="/opt/anaconda3/bin:$PATH"
     fi
 fi
 unset __conda_setup
 # <<< conda init <<<

Then I added the line:

 export PATH=/opt/anaconda3/bin:$PATH

This did not solve it. When I instead used any of the lines:

 export PATH=~/anaconda3/bin:$PATH
 export PATH=$PATH:$HOME/anaconda3/bin
 export PATH=$PATH:$HOME/opt/anaconda3/bin

this did not solve it either.

In a terminal window, I also tried to run the conda command in various folders/directories, especially /anaconda3 sub-folders, but no luck either.

Every time I open terminal and try to run conda --version to see if it works, it says: conda: Command not found. I don't know what to do anymore. Could anyone help, please?


Solution

  • Since macOS 10.15, the default shell is not bash, but zsh. It might explain why modifying your .bashrc did not help.

    According to the FAQ, what you should do in case conda was not set up correctly is not to modify the PATH variable manually, but instead try to run

    source <path to conda>/bin/activate
    

    This will activate the base environment and make sure that conda is set up correctly for the current session. This can be followed by:

    conda init
    

    to ensure that conda is added to the correct files for the current terminal, which might be zsh in your case and not bash