How do I use brew installed Python as the default Python?

Python Programming

Question or problem about Python programming:

I try to switch to Homebrew (after using fink and macport) on Mac OS X 10.6.2. I have installed python 2.7 with

brew install python 

The problem is that, contrary to Macport, it seems that there is no python_select utility, and my default mac python is always default

which python

give me


and /usr/bin/python is not a symlink

How can I do to make python brew flavour to be my default python ?

How to solve the problem:

Solution 1:

As you are using Homebrew the following command gives a better picture:

brew doctor


==> /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by
Homebrew. This is an issue if you eg. brew installed Python.
Consider editing your .bash_profile to put: /usr/local/bin ahead of
/usr/bin in your $PATH.

Solution 2:

See: How to symlink python in Homebrew?

$ brew link --overwrite python Linking /usr/local/Cellar/python/2.7.3... 28 symlinks created $ which python /usr/local/bin/python 

Solution 3:

As suggested by the homebrew installer itself, be sure to add this to your .bashrc or .zshrc:

export PATH="/usr/local/opt/python/libexec/bin:$PATH" 

Solution 4:

Quick fix:

  1. Open /etc/paths
  2. Change the order of the lines (highest priority on top)

In my case /etc/paths looks like:

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

If you want to know more about paths in OSX I found this article quite useful:

Solution 5:

I did “brew install python” for OSX High Sierra. The $PATH had /usr/local/bin before any other path but still which python was pointing to the system’s python.

When I looked deeper I found that there is no python executable at /usr/local/bin. The executable is named python2. To fix this problem create a symbolic link python pointing to python2:

/usr/local/bin $: ln -s python2 python

Hope this helps!