I am coming from an Ubuntu environment, and since you can set Python 3 to be the first-class Python in Ubuntu (as in, you call python and you get Python 3), I wanted to do the same on the Mac I've started using.

After trying to point the /usr/bin/python symbolic link to /usr/bin/python3 and finding it failed, I did some research and found that Apple puts some protection on /usr/bin which has to be updated by changing a flag in Recovery mode, and is not generally recommended. So I thought I would create a new /usr/bin/local/python link to /usr/bin/python3 and that would work since /usr/bin/local/python comes before /usr/bin/python in the path.

Here's what I've tried. The results have me confused.

username@Machine ~ % python --version
Python 2.7.18
username@Machine ~ % sudo rm /usr/local/bin/python
username@Machine ~ % sudo ln -s /usr/bin/python3 /usr/local/bin/python
username@Machine ~ % which python
username@Machine ~ % python --version
Python 2.7.18
username@Machine ~ % echo $PATH
username@Machine ~ % /usr/bin/python3 --version
Python 3.8.9
username@Machine ~ % ls -l /usr/local/bin/python
lrwxr-xr-x  1 root  wheel  16 Dec  9 12:37 /usr/local/bin/python -> /usr/bin/python3
username@Machine ~ % hash -r
username@Machine ~ % python --version
Python 2.7.18
username@Machine ~ % whence python   

I should add that I'm running zsh, and I'm used to running bash. Why don't I get version 3.8.9 when I run python --version or /usr/local/bin/python --version?

  • What does type python return after running hash -r?
    – nohillside
    Dec 9, 2021 at 22:14
  • As you probably know, this is easy to fix on a Linux box with update-alternatives. I use MacPorts instead of Homebrew, but unfortunately there is no MacPort for update-alternatives - perhaps there is for Homebrew??
    – Seamus
    Dec 11, 2021 at 6:30
  • Given that Python 2 and Python 3 have so many incompatibilities, I find your approach a bit questionable. You could for instance put a directory in front of your PATH, and in that direcory you create a symbolic link python, pointing to your python3 installation. Another possibility (if you plan to use this feature only interactively) would be to create a function or an alias. Dec 22, 2021 at 9:35
  • I've decided to let this go and just use pyenv instead.
    – k-den
    Dec 23, 2021 at 18:23
  • @Seamus but for macports you don't need this - use port select to choose which python to use
    – mmmmmm
    Dec 23, 2021 at 18:31

1 Answer 1


Because you didn't re-hash the shell you are currently in. Either use:

% hash -r

Or restart the shell.

/usr/bin/which does not tell you what the shell is going to do, because it is not a shell builtin... it searches $PATH.

If you want to know what the shell is actually going to do, use whence, which is a shell builtin.

Having said this, since you have decided to use Homebrew, why aren't you using Homebrew's python? Python 3.8.9 is the one from the Apple CLT.

  • I did try exiting the terminal and restarting before making this post. I ran the other commands you suggested, but I seem to be having the same problem. I've added the output to the question.
    – k-den
    Dec 9, 2021 at 22:03
  • I've decided to let this go and just use pyenv instead.
    – k-den
    Dec 10, 2021 at 17:58
  • because it is not a shell builtin : This is not entirely true. The OP unfortunately tagged the question by bash and zsh, which of course is a bad idea in the first place; but in zsh, which is a builtin. In bash it is not. Dec 22, 2021 at 9:38
  • It isn't in ksh either. Dec 22, 2021 at 14:47
  • @MarcWilson which is a builtin command in zsh see the manual zsh.sourceforge.io/Doc/Release/…
    – mmmmmm
    Dec 23, 2021 at 18:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .