Skip to main content

Command Palette

Search for a command to run...

Restoring Python 2 on macOS 12.3 and Higher

In just a couple of straightforward commands

Updated
2 min read
Restoring Python 2 on macOS 12.3 and Higher
A

Software Engineer and Team Leader with a robust background in CI/CD, automation, developer tooling and proven problem-solving expertise. Committed to combining technical knowledge with a product management mindset to drive goals and product improvements during the development process. Consistent record of achievement building and integrating automation to facilitate seamless CI/CD pipelines, leading to improved time-to-market.

Just a very quick post today! I will be writing some more detailed posts about various topics soon, but things have been so busy over at CircleCI recently.

Apple recently released macOS 12.3 and, in the process, removed Python 2 from macOS entirely. Python 2 has been deprecated, and EOL, for several years now (Homebrew deleted the formula some time ago), so the removal of it from the base OS is no real surprise.

As always, I would encourage everyone to migrate to Python 3 for better long-term support, but if you have scripts that absolutely must use Python 2, then this can be added back to macOS in a couple of commands.

Adding Python 2 back to macOS

The Python project still hosts the final Python 2 macOS installer package, so we can simply download and install this to restore Python 2 to macOS. It is simple and quick to do this entirely from the command line:

curl -O https://www.python.org/ftp/python/2.7.18/python-2.7.18-macosx10.9.pkg
sudo installer -pkg python-2.7.18-macosx10.9.pkg -target /

Example:

Screenshot 2022-04-14 at 10.49.13.png

It is as simple as that. Python 2 will now be available again via the python command and will live happily side by side with the system Python 3 installation (which is the python3 command)

This also works in CircleCI, where Python 2 is no longer available from Xcode 13.3 onwards:

Screenshot 2022-04-14 at 10.53.22.png

Happy Building!

110 views