Remove the third-party Python 2.7 framework directory (/Library/Frameworks/Python.framework/Versions/2.7), its /Applications/Python 2.7 folder, and any broken symbolic links inside /usr/local/bin pointing to that framework—while never touching /usr/bin/python* or /System/Library/Frameworks/Python.framework, which are protected by Apple’s System Integrity Protection (SIP) on older macOS versions (up to macOS 12.2) or completely absent on macOS 12.3+.
Basic Example
# 1. Inspect where `python` / `python2` currently resolves before deleting anything:
which -a python python2
ls -l /usr/local/bin/python*
# 2. Recommended: Remove the official Python.org 2.7 framework and GUI Applications folder
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
# 3. Remove ONLY symlinks inside `/usr/local/bin` that point into Python 2.7:
find /usr/local/bin -maxdepth 1 -type l -lname '*/Python.framework/Versions/2.7/*' -delete
# 4. If Python 2.7 was installed via Homebrew instead, uninstall via `brew`:
brew uninstall --ignore-dependencies python@2 2>/dev/null || true
Key Details & Edge Cases
- Never run
sudo rm -rfon/System/Library/Frameworks/Python.frameworkor/usr/bin:- Apple removed the built-in system Python 2.7 in macOS Monterey 12.3 (2022). On older macOS versions (10.15 Catalina through 12.2),
/System/Library/Frameworks/Python.frameworkis locked by System Integrity Protection (SIP) and required by legacy OS utilities—only delete user-installed Python 2.7 under/Library/Frameworks/Python.framework/Versions/2.7(without/Systemin front!).
- Apple removed the built-in system Python 2.7 in macOS Monterey 12.3 (2022). On older macOS versions (10.15 Catalina through 12.2),
- Do not delete the entire
/Library/Frameworks/Python.frameworkparent folder if Python 3.x is also installed:- Official Python.org installers for Python 3.11, 3.12, etc., install side-by-side inside
/Library/Frameworks/Python.framework/Versions/3.12/. Deleting the parentPython.frameworkfolder instead ofVersions/2.7will wipe out all Python.org Python 3 installations as well.
- Official Python.org installers for Python 3.11, 3.12, etc., install side-by-side inside
- Clean up stale
PATHexports in~/.zshrcor~/.bash_profile:- The Python.org 2.7 installer appends a block (
# Setting PATH for Python 2.7$\rightarrow$export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}") to~/.zprofile,~/.zshrc, or~/.bash_profile. Open those files and delete those lines so your shell does not search a nonexistent directory on every command.
- The Python.org 2.7 installer appends a block (
- Remove leftover user-level site-packages and pip caches (
~/Library/Python/2.7):- Packages installed via
pip install --userunder Python 2.7 live in~/Library/Python/2.7. Remove that directory cleanly withrm -rf ~/Library/Python/2.7.
- Packages installed via
- Verify that Python 3 remains intact afterward:
- Open a fresh Terminal window and run
which -a python3andpython3 --versionto confirm your Python 3 installation (Homebrew,pyenv, or Python.org 3.x) still resolves cleanly.
- Open a fresh Terminal window and run
Comparison of macOS Python 2.7 Locations & Safe Removal Actions
| Location / Installation Source | Safe to Delete? | Exact Removal Command | Best Used When |
|---|---|---|---|
/Library/Frameworks/Python.framework/Versions/2.7 & /Applications/Python 2.7 (Recommended) |
Yes | sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7 "/Applications/Python 2.7" |
Uninstalling an official Python.org 2.7 .pkg installer without affecting Python 3.x. |
Broken Symlinks in /usr/local/bin (python, python2, pip2, idle2) |
Yes (only links targeting 2.7) |
find /usr/local/bin -maxdepth 1 -type l -lname '*/Python.framework/Versions/2.7/*' -delete |
Cleaning up dangling CLI binaries left behind after removing the 2.7 framework. |
~/Library/Python/2.7 (User site-packages) |
Yes | rm -rf ~/Library/Python/2.7 |
Reclaiming disk space from legacy --user pip packages installed under Python 2.7. |
/System/Library/Frameworks/Python.framework (Apple OS Python) |
No (Never delete) | Do not touch (protected by macOS SIP; already removed by Apple in macOS 12.3+) | Always leave /System/... untouched to avoid breaking macOS integrity. |
You must log in or register to comment.
