Homebrew
Python 2
reinstall
macOS
package management

How to reinstall python2 from Homebrew?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Reinstalling Python 2 with Homebrew is a legacy-maintenance task, not a normal modern setup. The main complication is that Python 2 reached end of life years ago, so whether Homebrew can reinstall it depends on what formulas or custom taps still exist in your local setup.

Check Whether a Formula Still Exists

Before trying to reinstall anything, ask Homebrew what it currently knows:

bash
brew list --versions
brew search python
brew info python@2

The important point is that brew reinstall can only work if there is actually a formula to reinstall. If brew info python@2 fails, the problem is not your command syntax. The problem is that the formula may no longer be available in your active Homebrew sources.

If you already have an older custom tap or extracted formula, brew info will usually make that obvious.

Reinstall When the Formula Is Available

If your Homebrew environment still has a usable Python 2 formula, the reinstall path is straightforward:

bash
brew reinstall python@2

If the installation is badly broken or partially removed, uninstalling first can be cleaner:

bash
brew uninstall --ignore-dependencies python@2
brew install python@2

After that, verify what the shell resolves:

bash
python2 --version
which python2
brew list --versions python@2

That verification matters because you may still have another Python 2 interpreter from an old framework install, pyenv, or a stale symlink.

When Homebrew No Longer Provides It

On many modern Homebrew setups, the default taps no longer provide a normal Python 2 formula. In that case, brew reinstall python@2 is not a real path forward.

Your practical options are usually:

  • use a previously extracted formula in a custom tap
  • use pyenv to install and isolate Python 2.7
  • run the legacy code inside Docker or a VM

For most teams, a contained legacy environment is safer than trying to revive Python 2 as a general-purpose system runtime on the host machine.

Keep the Legacy Runtime Isolated

If you do get Python 2 working, avoid making it the default development Python. A safer pattern is:

  • call it explicitly as python2
  • use python2 -m pip instead of plain pip
  • keep the environment tied to the one project that still needs it

That reduces the chance of polluting modern Python 3 workflows with unsupported packages and outdated tooling.

Verify pip Against the Same Interpreter

Once the interpreter is back, confirm that its package manager points to the same runtime:

bash
python2 --version
python2 -m pip --version
python2 -c "import sys; print(sys.executable)"

Using python2 -m pip is the safest habit because it removes ambiguity about which interpreter owns the installation target.

Common Pitfalls

The biggest mistake is assuming brew reinstall python@2 must work on every current Homebrew installation. For many systems, the formula simply is not present anymore.

Another common issue is reinstalling Python 2 globally when the real need is one old build step or deployment script. In that case, pyenv or a container is usually a cleaner answer.

It is also easy to check only the version string and miss the executable path. Always verify which python2 binary the shell is actually using.

Summary

  • Reinstalling Python 2 with Homebrew only works if your Homebrew setup still has a usable Python 2 formula.
  • Start with brew info, brew search, and installed-version checks before running reinstall commands.
  • If the formula exists, brew reinstall python@2 or uninstall plus install is the normal path.
  • If it does not exist, use a legacy-friendly fallback such as a custom tap, pyenv, or Docker.
  • Keep Python 2 isolated and verify both the interpreter path and its pip environment afterward.

Course illustration
Course illustration

All Rights Reserved.