The easiest way to get Anaconda to work on a Mac (the right way)

Vu Nguyen
5 min readAug 5, 2020

--

An absolute beginner guide to installing Anaconda the right way and fixing “ command not found: conda”

Photo by Pexels.com. Edited by the Author

There are numerous tutorials on how to install Anaconda and get it to run in terminal. Nevertheless, I wouldn’t call them beginner guide and I still have to spend hours fixing “conda command not found” error (partly I didn’t know what to do). Hence, I decided to write this tutorial hoping this can save you hours of wandering on Google.

Hold on, why do I need Anaconda?

Anaconda is a package and environment manager for Python and R. With Anaconda and conda command, you can quickly install, run and update packages along with their dependencies. You can also change your environment (aka Python version) in case a package requires different version of Python.

For more information about conda features, you can check the official getting started guide here.

Why I can’t just follow the official guide?

The official guide is quite comprehensive in the sense that it include almost all operating system out there.

You follow the guide, then, at the end, it tells you to verify your installation with conda list.

And OOPS!

Something went wrong 😭

The shell cannot locate Conda

What went wrong?

The installation was successful. However, the problem is that your current shell cannot find conda. To fix this, you need to tell your shell where to locate conda.

So why do I still need to run Anaconda in the Terminal?

If installation was successful, it’s end of story? Not really.

1️⃣ Upon checking your Python version, it’s still the old version packaged with MacOS.

Shell still uses Python 2.7.16 that come with MacOS

2️⃣ Moreover, some packages (etc. tensorflow, keras) require pip to install correctly, but the shell cannot find pip either.

3️⃣ Although you can do pretty much everything you can in Anaconda shell with Anaconda Navigator, Anaconda shell is both faster and more reliable.

Sometimes, when you change your environment setting in the desktop app, the process bar will run forever

The Fix

*****RESTART YOUR TERMINAL*****

Before doing anything, restart your terminal. According to a former Anaconda engineer, the most common reason is because “people are not refreshing their shell session.” So, quit and reopen your terminal!

Step 1: Install Anaconda like you always do

You can skip this step if you already install Anaconda. I re-use some images from the official guide.

1. Go here to download Anaconda. To make in plain simple, download the Graphical Installer.

2. Double click the file and keep clicking Continue.

3. Agree to the terms of software (I doubt that you will read the license)

Image by author

4. Click Install so that Anaconda will be installed in your ~/opt directory

Image by Anaconda

5. Select Install for me only (to avoid any complications)

Image by Anaconda

6. Click Continue, you can explore PyCharm at another time

Image by Anaconda

7. Done

Image by Anaconda

Step 2: Locate conda file/where you install Anaconda

If you didn’t change installation directory in the previous step, it should be in:

/Users/YOUR_USER_NAME/opt/anaconda3/bin/conda

In my case, it is:

/Users/vunguyen/opt/anaconda3/bin/conda

You can use whoami if you don’t know your user name:

/Users/$(whoami)/opt/anaconda3/bin/conda

You can also use echo $USERto print out the user name

Image by author

If you already know where the conda file is, skip to Step 3

If you changed the installation directory and not sure where it is, go to Finder and search for “anaconda3” folder

1. Type anaconda3 in the search bar

2. Click the Gear icon then click Show Search Criteria

Image by author

3. Select Kind as Folder

Image by author

4. There should be a folder in your directory named anaconda3

Image by author

5. Double-click the anaconda3 folder, then go to bin folder. There, you should see the conda file

Image by author

Step 3: conda init YOUR_COMMAND_SHELL

Simply drag the conda file into your favorite terminal then type “ init YOUR_COMMAND_SHELL”

/Users/$(whoami)/opt/anaconda3/bin/conda init YOUR_COMMAND_SHELL
dragging the file into terminal will show the full path

To determine YOUR_COMMAND_SHELL, the easiest way is to look at the top of terminal windows. In my case, it’s zsh (this is also the default Shell for Catalina)

Image by author

Or, you can type echo $SHELL

Image by author

For zsh:

YOUR_PATH_TO_anaconda3/bin/conda init zsh

if you haven’t changed the conda installation destination:

/Users/$(whoami)/opt/anaconda3/bin/conda init zsh
Image by author

For bash:

YOUR_PATH_TO_anaconda3/bin/conda init bash

if you haven’t changed the conda installation destination:

/Users/$(whoami)/opt/anaconda3/bin/conda init bash
Image by author

Now close and re-open Terminal.

And finally! I mean finally:

Verifying your installation

conda list
Image by author
pip --version

Use python --version and which python to check version and location of python

Now you can install and manage packages with both conda and pip command.

Thank you for reading!

Please leave a clap or comment if you find this helpful 😃

--

--