How to reinstall python@2 from Homebrew? How to reinstall python@2 from Homebrew? python python

How to reinstall python@2 from Homebrew?


It seems that the homebrew staff really makes it as hard as possible to use Python 2.7 on macOS as they can.

  1. The linked brew extract link is really not helpful, you need to look for answers here about how to make your own tap from extracted sources.
  2. The linked commit: 028f11f9e is wrong, as it contains the already deleted file.
  3. The brew extract command doesn't even work correctly, because of the @ in the package name.

The solution is very simple though, you just need to download the latest known commit and install from that file:

cd ~wget https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rbbrew install python@2.rbrm python@2.rb

There might be a warning about this being "unstable", which I don't understand as a commit in a Git history is as stable as you can get.


How to install python@2 from a local tap

The following method works with the current version (c9b8a3ef6) of brew:

$ brew tap-new <user>/homebrew-python2$ brew extract python@2 <user>/homebrew-python2$ brew install /usr/local/Homebrew/Library/Taps/<user>/homebrew-python2/Formula/python@2.7.17.rb

The brew tap-new command creates a new local tap template in /usr/local/Homebrew/Library/Taps/<user>/homebrew-python2. The tap name needs a <user> and a <repo> component separated by a /. The actual values are arbitrary. The naming above follows the conventions from How to Create and Maintain a Tap. If you wanted to push the tap to GitHub you would use your GitHub username as user. Pushing to GitHub is not necessary (and was not performed in the instructions above).

The brew extract commands extracts the recent version of formula from the repos history into the given (local) tap. In our case python@2.7.17.rb is extracted.

The brew install command finally installs the formula.

Why is this necessary?

The method discussed above (installing an old version of the formula from a GitHub commit URL) does not work anymore for python@2 with the current version of brew (c9b8a3ef6), it produces the following error:

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rbUpdating Homebrew...==> Auto-updated Homebrew!Updated Homebrew from 88f17b8b6 to c9b8a3ef6....Error: Calling Installation of python@2 from a GitHub commit URL is disabled! Use 'brew extract python@2' to stable tap on GitHub instead.


You can use pyenv to install python with:

brew install pyenvpyenv install 2.7.18

Optionally set it to your global default:

pyenv global 2.7.18

Nice article on why using pyenv is better than using brew to manage your python installation.