How to default Python 3.8 on my Mac using Homebrew

Hi, I have updated my python 3 to the latest version 3.8:

brew search python
==> Formulae
app-engine-python   gst-python          python ✔            python@3.8 ✔
boost-python        ipython             python-markdown     wxpython
boost-python3       micropython         python-yq

==> Casks
awips-python               kk7ds-python-runtime       mysql-connector-python

But when I check the python3 version on my mac it still shows 3.7:

python3 --version

Python 3.7.6

how can I default python3 to the latest 3.8 version using Homebrew ?

When I tried to use brew switch, it tells me I only installed python 3.7.6, but with last brew upgrade I’m pretty sure that python3.8.1 is installed with Homebrew

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

There’s a much less disruptive way, that’s already documented in the python@3.8 formula:

$ brew info python@3.8
python@3.8: stable 3.8.1 (bottled) [keg-only]
==> Caveats
Python has been installed as
python@3.8 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have python@3.8 first in your PATH run:
  echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.bash_profile

For compilers to find python@3.8 you may need to set:
  export LDFLAGS="-L/usr/local/opt/python@3.8/lib"

For pkg-config to find python@3.8 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/python@3.8/lib/pkgconfig"

Set your PATH (and LDFLAGS and PKG_CONFIG_PATH if needed) as described above, and no switching/relinking is needed.

You could alternatively brew unlink python and brew link --force python@3.8, but that “forcing” option is a big hint that subsequent things may not go well.

1 Like

Ok, will this conflict with the Python 3 kernel on Jupyter Notebook ?

Currently the Python 3 kernel running on Jupyter Notebook is Python3.7.6

And by the way I have all the python3 packages installed in the /usr/local/lib/python3.7/site-packages directory, will all these packages be safely preserved if I change Python3.7.6 to Python3.8.1 ?

You’d have to try it to find out.

Not a Python guru, but the answer’s almost certainly no, because python@3.8 is a completely different entity from python, not just a different version of the same package. You’d have to change your PATH first, then reinstall your Python3 stuff.

I’d suggest sticking to python (v3.7.6) unless you absolutely must use the bleeding edge, because it’ll probably be upgraded seamlessly to v3.8 in the near future.

1 Like

Got it, I will stick to my current Python3.7.6.

Thanks a lot !