Explain Codes LogoExplain Codes Logo

How to reinstall python@2 from Homebrew?

python
pyenv
python-installation
homebrew
Nikita BarsukovbyNikita Barsukov·Jan 18, 2025
TLDR

To reinstall python@2 after its removal from Homebrew, you can use a third-party tap or extract from an old formula. Execute these commands:

brew tap-new $USER/local-python2 # Create custom tap named local-python2 brew extract --version=2.7.18 python@2 $USER/local-python2 # Extract python@2 like taking juice from one orange to another brew install $USER/local-python2/python@2 # Install python@2 from local tap - kind of homemade beer!

Let's not forget: upgrading to Python 3 is highly recommended due to Python 2's end of life.

Pyenv: Manage Python the Boss Way

When dealing with deprecated Python versions, remember pyenv is your friend. This tool offers amazing features to manage multiple Python versions in a consolidated and tidy manner.

  1. Install Python versions like a breeze.
  2. Switch between Python versions like changing TV channels.
  3. Set a global default Python, handy for maintaining consistency across terminal sessions.
  4. Isolate Python environments for each project, prevents Python vs Python battles.

Walking you through Python workflow

Ensuring smooth operation of awscli

Some formulas, such as awscli, required Python 2. If it's not working as expected, using pyenv allows different environments for each application to sidestep this problem.

@ symbols and formulas

Homebrew commands can get tripped up by formula names with a pesky @ symbol. Using local taps and specific URLs for installation can outsmart this pitfall.

Compatibility with macOS

Before resuscitating Python 2, make sure your macOS version is in agreement. Compatibility is key to preventing unforeseen hiccups.

Keeping up with Homebrew evolution

Homebrew is like the universe - always expanding and becoming more complex. To stay on top, make sure to read the Homebrew documentation regularly.

Overcoming Homebrew limitations

If you run into a brick wall with Homebrew's evolving nature, broaden your horizon and consider alternative Python installation methods.