34

macOS 12.3 update drops Python 2 and replaces it with version 3:

https://developer.apple.com/documentation/macos-release-notes/macos-12_3-release-notes

Python Deprecations Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)

I understand we need to migrate to version 3, but in the meantime we still need version 2. Homebrew does not seem to have it anymore:

brew install python@2.7
Warning: No available formula with the name "python@2.7". Did you mean python@3.7, python@3.9, python@3.8, python@3.10 or python-yq?

brew install python2
Warning: No available formula with the name "python2". Did you mean ipython, bpython, jython or cython?

What gives?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
rmp251
  • 5,018
  • 4
  • 34
  • 46

3 Answers3

74

You can get any Python release, including the last Python 2, from the official download site:

https://www.python.org/downloads/release/python-2718/macOS 64-bit installer

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
12

A bit more relevant information. It was removed due to the fact that macOS remove the support of python2, and there is an open issue to remove all the python2 formulae as well.

Instead of using python official installer, I would suggest using pyenv, which is easier to manage multiple python versions in your local.

chenrui
  • 8,910
  • 3
  • 33
  • 43
  • 4
    I tried pyenv. It builds from source, which isn't convenient, and in my case it failed for whatever reason. `dlopen(build/lib.macosx-12.6-arm64-2.7/gdbm.so, 0x0002): symbol not found in flat namespace (_gdbm_close)`. Ended up just downloading from python.org in the end. I'm probably not install multiple Py2 versions, but if I do, it's easy enough to switch on-demand using `ln -sf /usr/bin/python2x /usr/bin/python`. – sudo Oct 08 '22 at 20:18
3

If, like me, you need it for development you should use PyEnv:

Here's a great tutorial: https://dev.to/jordicuevas/how-to-install-python2-in-a-macbook-m1-with-brew-bhi

TL;DR:

npm install

brew install pyenv

pyenv install 2.7.18

export PATH="$(pyenv root)/shims:${PATH}"

echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

pyenv init

(Follow instructions provided. I had to add to ~/.zprofile and ~/.zshrc.)

Make sure you load the changes by running source ~/.zprofile and source ~/.zshrc.

pyenv shell 2.7.18

Now, the python command should target Python 2 in the shell/Terminal.

Lindauson
  • 2,963
  • 1
  • 30
  • 33