Heading image for post: Keep Anaconda from Constricting Your Homebrew Installs

Keep Anaconda from Constricting Your Homebrew Installs

Profile picture of Ifu Aniemeka

Fixing conflicts between Anaconda and Homebrew

I recently installed Anaconda to my local machine and noticed that Anaconda modified my PATH variable. For Mac installations, if you check your .bash_profile, you should see something like the following:

# Added by Anaconda3 4.4.0 installer
export PATH="/Applications/anaconda/bin:$PATH"

Now if you run brew doctor, you'll get the following gnarly message:

Warning: Anaconda is known to frequently break Homebrew builds, including Vim and
MacVim, due to bundling many duplicates of system and Homebrew-available
tools.

If you encounter a build failure please temporarily remove Anaconda
from your $PATH and attempt the build again prior to reporting the
failure to us. Thanks!

Warning: python is symlinked to python3
This will confuse build scripts and in general lead to subtle breakage.

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
  /Applications/anaconda/bin/curl-config
  /Applications/anaconda/bin/freetype-config
  /Applications/anaconda/bin/icu-config
  /Applications/anaconda/bin/libpng-config
  /Applications/anaconda/bin/libpng16-config
  /Applications/anaconda/bin/python3-config
  /Applications/anaconda/bin/python3.6-config
  /Applications/anaconda/bin/python3.6m-config
  /Applications/anaconda/bin/xml2-config
  /Applications/anaconda/bin/xslt-config

Basically, the universe will collapse upon itself because you thought it might be cool to try a Kaggle competition.

Damn.

Fortunately, the message includes a fix - remove Anaconda from $PATH, run brew, then add Anaconda back to $PATH. Having said that, doing that every time I use Homebrew sounds like a pain in the backside.

So here's a bash script to do it for you so you can keep on being lazy.

export SANS_ANACONDA="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

# added by Anaconda3 4.4.0 installer
export PATH="/Applications/anaconda/bin:$SANS_ANACONDA"

alias perseus="export PATH="\$SANS_ANACONDA" && echo Medusa decapitated."
alias medusa="export PATH="/Applications/anaconda/bin:\$SANS_ANACONDA" && echo Perseus defeated."

brew () {
  perseus
  command brew "$@"
  medusa
}

There are aliases for the addition and removal of Anaconda from $PATH to make doing it manually even easier.

Happy (data science) coding!

Photo by Samuel Zeller on Unsplash

  • Adobe logo
  • Barnes and noble logo
  • Aetna logo
  • Vanderbilt university logo
  • Ericsson logo

We're proud to have launched hundreds of products for clients such as LensRentals.com, Engine Yard, Verisign, ParkWhiz, and Regions Bank, to name a few.

Let's talk about your project