Revert Python Version in Mac (Homebrew)

Homebrew upgrades packages to the latest versions whenever it tries to install a package. This has caused problems multiple times for me especially with the Python version.

Recently Homebrew upgraded Python version on my Mac from 3.8 from 3.9. This has caused problems with gcloud. I installed python 3.8 version using brew install python@3.8. The installation was successful but python3 still referring to the newer version i.e python 3.9.

The trick is to update the PATH to use Python 3.8. I’ve performed the following steps to revert Python version to Python 3.8.

  1. brew info python@3.8 After you run this command you will see lot of information, find the following lines
If you need to have python@3.8 first in your PATH run:
  echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.zshrc
  1. Execute the command as-is echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.zshrc

  2. Refresh your shell, zsh -l In my case it is zsh. You can also close and open your terminal.

  3. Run python3 --version. You should see Python 3.8.X.