Joe
Joe

Reputation: 13101

What is the best way to Install Conda on MacOS (Apple/Mac)?

What is the recommended approach for installing Anaconda on Mac?

I tried with brew cask install anaconda
which after a while returns anaconda was successfully installed!.

After that - trying conda command returns command not found: conda.

Is there any post step installation that needs to be done?
And what is recommended way to install Conda on MacOS?

Upvotes: 46

Views: 86106

Answers (5)

Mobiletainment
Mobiletainment

Reputation: 23261

First run brew install anaconda

Then run which anaconda to find the path to export.

  • export PATH="/usr/local/anaconda3/bin:$PATH"

For Mac M1

  • export PATH="/opt/homebrew/anaconda3/bin:$PATH"

Upvotes: 62

Rishit Ratan
Rishit Ratan

Reputation: 1

The directory path of your conda installation can depend on various factors, hence copy pasting directories and asking them to export that as their paths might not work. Do this instead:

$ brew install -cask anaconda
$ cat ~/.conda/requirements.txt
/example/directory/anaconda3
$ export PATH="/example/directory/anaconda3/bin:$PATH"
$ conda --help
usage: conda [-h] [--no-plugins] [-V] COMMAND ...

conda is a tool for managing and deploying applications, environments and packages.

options:
  -h, --help          Show this help message and exit.
  --no-plugins        Disable all plugins that are not built into conda.
  -V, --version       Show the conda version number and exit.
.
.

Upvotes: 0

Charlie Parker
Charlie Parker

Reputation: 5291

New answer using only the terminal for mac zsh

This is how I did it only using the terminal and apple's now default zsh:

# - install python
# install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#  install wget to get miniconda
brew install wget

# get miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

# source /Users/my_username/opt/anaconda3/bin/activate
source ~/miniconda/bin/activate
conda init zsh
conda update -n base -c defaults conda
conda install conda-build

conda create -n iit_synthesis python=3.9
conda activate iit_synthesis
#conda remove --name metalearning2 --all

inspired from: How do I use Conda in on Homebrew Python system?


Old answer

I don't know about other people but I've had issue downloading conda/miniconda etc for a few hours now. For some reason it decided to install at ~/opt when using the graphical installer (i.e. the .dmg file). I've been through the uninstall here How to uninstall Anaconda completely from macOS and additionall did an rm -rf ~/opt command. Seems that without this its not actually uninstalled (you might also have to change your PATH or .bash_profile or .bashrc until your path is virigin again before you start your re-installation installation). Seems that using the command line installer is what works:


Anaconda3 will now be installed into this location:
/Users/brandBrandoParetoopareto/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/Users/brandBrandoParetoopareto/anaconda3] >>> 
PREFIX=/Users/brandBrandoParetoopareto/anaconda3

Unpacking payload ...
Collecting package metadata (current_repodata.json): done                                                                                                                                                                                                                                                                                            
Solving environment: done

So for that download it from the official link then do:

sh Anaconda3-2020.02-MacOSX-x86_64.sh 

do sh I believe is the right thing because I might have had issue in the past when I did bash instead...plus if you are using a different shell like zsh I am not sure what you'd need to do, but I'd get sh would be safest.

After the installation is done you should do:

conda init <SHELL-NAME>

so that conda is initialized correctly (so far that seems to only modify my .bash_profile and my PATH variable). Unfortunately, it seems the previous uninstallation attempts didn't remove the code the previous conda init had added from my .bash_profile so I removed it manually using vim.

This is what I get after doing that:

conda init bash

no change     /Users/brandBrandoParetoopareto/anaconda3/condabin/conda
no change     /Users/brandBrandoParetoopareto/anaconda3/bin/conda
no change     /Users/brandBrandoParetoopareto/anaconda3/bin/conda-env
no change     /Users/brandBrandoParetoopareto/anaconda3/bin/activate
no change     /Users/brandBrandoParetoopareto/anaconda3/bin/deactivate
no change     /Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.sh
no change     /Users/brandBrandoParetoopareto/anaconda3/etc/fish/conf.d/conda.fish
no change     /Users/brandBrandoParetoopareto/anaconda3/shell/condabin/Conda.psm1
no change     /Users/brandBrandoParetoopareto/anaconda3/shell/condabin/conda-hook.ps1
no change     /Users/brandBrandoParetoopareto/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change     /Users/brandBrandoParetoopareto/anaconda3/etc/profile.d/conda.csh
modified      /Users/brandBrandoParetoopareto/.bash_profile

==> For changes to take effect, close and re-open your current shell. <==

if you are using vs-code integrated terminal like I am you need to press the trash can button. Doing bash seems to NOT re-run your .bash_profile so make sure you do what it would consider "closing your terminal and re-opening it completely".

That should be all you need to do I believe. Perhaps you also need to make sure you have the most recent version of mac OS.


Extra tips hints

  • Make sure conda init modified your .bash_profile correctly. For me for some reason it added it's stuff AFTER it ran my .bashrc and thus when my .bashrc tried activating my environment it wouldn't do it as it would say conda wasn't initialized correctly (and thus nio matter how many times I re-ran conda init <SHELL> it wouldn't fix it. I don't know why that happened but that's how it was.

  • I avoided the dmg/graphical installation since it seemed to install it at non-standard places ~/opt

  • If conda is still acting weird it might be because of the way your .bashrc modifies the PATH env variable. What worked for me was removing lines that modified my path in .bashrc (AND having the code conda init added before my .bashrc was ran).


inspired from:

Upvotes: 3

SteLab
SteLab

Reputation: 53

After installation using the graphical installation, everything sits in the ~/opt directory, as mentioned in some previous answers. If this is OK for you, all you need to do to use the command line conda is add ~/opt/anaconda3/bin in your path. This can be done by adding

export PATH="${PATH}:~/opt/anaconda3/bin"

at the end of your rc file (~/.zshrc or ~/.bashrc).

Upvotes: 0

sacuL
sacuL

Reputation: 51335

I would say that the recommended way to install anaconda is to use the official anaconda installer, which can be downloaded from the link I just posted. I've done it several times, never had a problem, and it walks you through it (including an option to automatically add it to your PATH).

Upvotes: 10

Related Questions