Mac using default Python despite Anaconda install

Solution 1:

The first matching executable is the one that is run. From what I can gather you are concatenating your PATH variable in such a way that:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

comes before:

$HOME/anaconda/bin

So make sure that the anaconda directory is the first one, meaning that it will have precedence:

export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

Solution 2:

If your default shell is sh (or possibly anything but bash) you won't be able to access your Anaconda python. If this is your case:

  1. Go to Terminal/Preferences
  2. Find 'Shells open with:'
  3. Click the button for 'Command (complete path)'
  4. Type /bin/bash as path

Restart your terminal. When you type $ which python you should now see the anaconda python. For me it was /Users/myname/anaconda3/bin/python.

$ echo $PATH will also change now to show to correct path, with anaconda first:

/Users/myname/anaconda3/bin:/Users/myname/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

In Atom I had to add a shebang to the beginning of each script to set this as my preference: #!/Users/myname/anaconda3/bin/python

Solution 3:

if you are using zsh you can edit in your zshrc file in your root folder to include

export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

Solution 4:

If you are using fish, you can find Anaconda backup your old .bash_profile as .bash_profile-anaconda.bak, and it added 2 lines at the bottom of .bash_profile which looks like this:

# added by Anaconda2 4.1.1 installer
export PATH="/Users/username/anaconda/bin:$PATH"

However fish does not read it, so you have to add it in fish config file manually, which is in ~/.config/fish/config.fish:

set -x PATH /Users/username/anaconda/bin $PATH