Installed Python 3 on Mac OS X but its still Python 2.7

Try typing python3 instead of just python.


While @rhombidodecahedron's answer is concise and to-the-point and @Nacho Izquierdo addresses your first question perfectly, my answer aims to answer your second question in some more detail:

One should not uninstall Python 2.7 which comes with Mac OS X; it is supplied by Apple and is needed for applications running on OS X. It is stored in /System/Library/Frameworks/... If it is removed, Mac OS X will have to be reinstalled.

Hope that helps! And to reiterate answers given by @rhombidodecahedron and @Nacho Izquierdo, install Python 3.x separately and use python3 if you would like to use that version.

Python 2.7 is the standard, Python 3.x is the future.


What you should not do -

moving default python binary to an unused name

$ sudo mv /usr/bin/python /usr/bin/python2

and then moving the new binary to the default path

$ sudo mv $PATHTOBINARY/python3 /usr/bin/python

What could be done but also shouldn't not be done

Since I use zsh by default, I put the following into the .zshrc file:

$ echo "alias python=/usr/local/bin/python3.7" >> ~/.zshrc

If you are using the default Bash shell, you can append this same text to your .bashrc:

$ echo "alias python=/usr/local/bin/python3.7" >> ~/.bashrc

This will work but it is not the recommended way because making future updates to Python will be difficult. It means we have to manually download the new files since Python doesn't include a command-line way to update.

What is the right way

The basic premise of all Python development is to never use the system Python. You do not want the Mac OS X 'default Python' to be 'python3'.

Usage of pyenv to manage Python environments is recommended.

$ brew install pyenv

$ pyenv install 3.7.3

$ pyenv global 3.7.3

$ pyenv version

Refresh the current terminal and check

$ python -V

It should give Python 3.7.3

This way you are good to go.

For further reference - https://opensource.com/article/19/5/python-3-default-mac


Since I know I'll only use python3, I added these 2 lines to .bash_profile file:

alias python="python3" # to use python3 rather than python2.7
alias idle="idle3" # to use python3 idle rather than 2.7