How to install python3.7 on a mac (mojave using homebrew

homebrewinstallpythonterminal

I am running MacOS Mojave (10.14.6) and want to install python 3.7.

Currently I have python 3.6 installed:

$ python -V
Python 3.6.9

There seems to be python 3.7 available:

$ brew search python
==> Formulae
app-engine-python            boost-python3                ipython                      python-markdown              python@3.7                   reorder-python-imports
boost-python                 gst-python                   micropython                  python-yq                    python@3.8 ✔                 wxpython
==> Casks
awips-python                                              kk7ds-python-runtime                                      mysql-connector-python

If you meant "python" specifically:
It was migrated from homebrew/cask to homebrew/core.

So I tried to install python 3.7 as follows

brew install python@3.7

with a lot of output. I also executed the suggested line to have python 3.7 symlinked:

echo 'export PATH="/usr/local/opt/python@3.7/bin:$PATH"' >> /Users/me/.bash_profile

I sourced the file .bash_profile, but still python is only 3.6:

$ python -V
Python 3.6.9

I also ran the following command with an error:

$ brew switch python 3.7
Error: python does not have a version "3.7" in the Cellar.
python's installed versions: 3.7.6_1

and restarted the computer, but without success.

So how to install python 3.7 as the standard-python-installation on a mac? (Could be also python3.8 by all means).

Best Answer

The following procedure worked for me (in addition to the commands in the original question):

brew uninstall --ignore-dependencies python3
brew uninstall --force python#3.8
brew install python3

and adding the following line to .bash_profile:

alias python="python3"

For a Mac this was really easy! Only about 10 commands.