OSX ships with an older version of Python. Install using Homebrew:

brew install python

This installs Python alongside the version in OSX. To access this version, it’s necessary to run:

➜ python --version
Python 2.7.16 # <- Still the old OSX version!

➜ python3 --version
Python 3.7.4 # <- This is the version we want

Similarly, use pip3 (instead of pip):

➜ pip --version
pip 19.1.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

➜ pip3 --version
pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

Finally, it’s necessary to add the path to Python 3.7 /bin, in ~/.zshrc or ~/.bash_profile:

# If you come from bash you might have to change your $PATH.
export PATH=/Users/<MYUSERNAME>/Library/Python/3.7/bin:$PATH

If you want to replace “python3” and “pip3” with “python” and “pip”, add this:

# /usr/local/opt/python/libexec/bin <- makes python3 the default when calling python
export PATH="/usr/local/opt/python/libexec/bin:$PATH"

After that, running “python” will use the newer version by default.