How To Reinstall Python@2 From Homebrew?
Solution 1:
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/python@2.rb
brew install python@2.rb
rm 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.
Solution 2:
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.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from88f17b8b6 to c9b8a3ef6.
...
Error: Calling Installation of python@2from a GitHub commit URL is disabled! Use 'brew extract python@2' to stable tap on GitHub instead.
Solution 3:
You can use pyenv
to install python with:
brew install pyenv
pyenv install 2.7.18
Optionally set it to your global default:
pyenv global2.7.18
Nice article on why using pyenv
is better than using brew
to manage your python installation.
Solution 4:
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/python@2.7.17 --build-from-source
Solution 5:
For posterity, working on macOS 10.15 (May/2021):
/usr/local/bin/brew tap-new ${USER}/homebrew-python2
/usr/local/bin/brew extract python@2 ${USER}/homebrew-python2
/usr/local/bin/brew install /usr/local/Homebrew/Library/Taps/${USER}/homebrew-python2/Formula/python@2.7.17.rb
# https://github.com/Homebrew/brew/issues/5734#issuecomment-464705002
/usr/local/bin/brew untap ${USER}/python2
Post a Comment for "How To Reinstall Python@2 From Homebrew?"