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.
- 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. - The linked commit: 028f11f9e is wrong, as it contains the already deleted file.
- 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/[email protected]
brew install [email protected]
rm [email protected]
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/[email protected]
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 [email protected]
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/[email protected]
Updating 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.
Please check following command (I am using it on macOS 10.13, it is possible that for a newer macOS it will work without source compilation):
brew install pr0d1r2/python2/[email protected] --build-from-source