31

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 ?

Edit: 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
Tack_Tau
  • 628
  • 1
  • 6
  • 12

4 Answers4

53

Here is the solution:

If existing symlinks belong to python 3.7 you should unlink them:
brew unlink python

Basically all you need to do:
brew link --force python@3.8

OR force the link and overwrite all conflicting files:
brew link --force --overwrite python@3.8

OR if needed list all files that would be deleted:
brew link --overwrite --dry-run python@3.8

Thus you can switch to any python version available in the Homebrew repo.

Also check out this answer for pyenv usage

Igor Voltaic
  • 742
  • 1
  • 7
  • 20
13

Ok, thanks to @gromgit from Homebrew community discussion (https://discourse.brew.sh/t/how-to-default-python-3-8-on-my-mac-using-homebrew/7050)

Here is the solution:

$ brew info python@3.8
python@3.8: stable 3.8.1 (bottled) [keg-only]
...
==> Caveats
Python has been installed as
  /usr/local/opt/python@3.8/bin/python3
...
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"

I will stick to python (v3.7.6) at this time and wait for seamless upgrade of v3.8.1 in the future releases.

Tack_Tau
  • 628
  • 1
  • 6
  • 12
3

I have a company Mac with Python 2.7 preinstalled to run older software.

$ brew install pyenv (successful)
$ pyenv install 3.9.2 (successful)
$ python --version
Python 2.7
$ pyenv global 3.9.2
$ python --version
Python 2.7 

It still says Python 2.7, so, I did the following commands

pyenv init
eval "$(pyenv init -)"

$ python --version
Python 3.9.2

More details: Link

JIANG
  • 1,687
  • 2
  • 19
  • 36
2

You might have to add python 3.8.1 to your PATH in your ~/.bash_profile and put it first so that it overrides previous installations. First find out where python 3.8.1 was installed, then add it to your path like this:

export PATH="/PATH_TO_PYTHON/:${PATH}"

James
  • 392
  • 4
  • 9
  • 1
    ```python@3.8: stable 3.8.1 (bottled) [keg-only] Interpreted, interactive, object-oriented programming language https://www.python.org/ /usr/local/Cellar/python@3.8/3.8.1 (4,127 files, 63.4MB)``` – Tack_Tau Feb 28 '20 at 14:23