2

I'm trying to install Homebrew with Python on a clean install of macOS High Sierra. HomeBrew successfully installed, as did python, pip etc into the /usr/local/bin folder and I've edited the /etc/paths to have /usr/local/bin at the top before /usr/bin but the terminal is still showing /usr/bin as the python version when using which python. I've tried restarting the terminal and system.

The exact same setup was working fine before I reinstalled the OS.

/etc/paths looks like this

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

EDIT: echo $PATH shows /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin but which python still shows /usr/bin/python

1

Modifying your system paths (in /etc/paths) is neither recommended nor needed.

If you've installed Python through Homebrew (brew install python and brew install python3), you should read the caveats carefully:

brew info python
brew info python3

Why is Homebrew's handling of python so special?

Check out the Homebrew and Python documentation, as Homebrew creates quite a few symlinks in different places and uses the following convention:

Homebrew provides one formula for Python 2.7.x and another for Python 3.x. The executables are organized as follows so that Python 2 and Python 3 can both be installed without conflict:

  • python points to the macOS system Python (with no manual PATH modification)
  • python2 points to Homebrew’s Python 2.7.x (if installed)
  • python3 points to Homebrew’s Python 3.x (if installed)
  • pip2 points to Homebrew’s Python 2.7.x’s pip (if installed)
  • pip3 points to Homebrew’s Python 3.x’s pip (if installed)

The reason for this is that you don't want python defaulting to Homebrew Python if it was installed as a dependency of some other formula, which could cause problems in scripts that simply use /usr/bin/env python in their shebang line.

Also note that this Homebrew/Python behavior may change at some point in the future, due to the legacy nature of Python 2.

But I want python to point to Homebrew's python!

So, if you really want to make python refer to Homebrew's Python 2.7 instead of your system Python, you should add that to your $PATH in ~/.bash_profile:

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

... and leave your /etc/paths as they were before.

  • I'll do it that way. I'm still curious why it isn't working editing /etc/paths though since that's how it was setup before the system reinstall and I still have a MacBook Pro (also running High Sierra although with a upgrade from Sierra rather than reinstall) that has it setup with the /etc/paths edit. – Flatlyn Oct 18 '17 at 13:58
  • 1
    Hm. To be honest, I don't know why it wouldn't work. Are you sure there's a python in /usr/local/bin? What does which -a python show? – slhck Oct 18 '17 at 14:48
  • Ah you're right. There isn't a python in /usr/local/bin only a python2, python2.7. The old systems presumably were setup with an older version of HomeBrew when a python was created in /usr/local/bin. Interestingly though there isn't a python3 or does that have to be installed separately with HomeBrew? I thought they came bundle together with brew install python – Flatlyn Oct 18 '17 at 15:04
  • 1
    No, you have to do brew install python3 to get it. – slhck Oct 18 '17 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.