macOS Sierra comes with a built-in default Python installation. On macOS Sierra 10.12.6, this default installation is on the /System/Library/Frameworks folder (which, by the way, is a critical system folder and should not be touched). macOS Sierra 10.12.6 comes with Python 2.7, which is getting outdated very fast, and also Apple itself recommends officially that to run a coding project, users should install their own updated version of Python with their own dependencies setup.
I had installed Python 2.7 myself last year when I was in a mood to start working on Python, and at that time I didn’t know that Python comes installed in macOS by default. Now I have to start working with Python in earnest for a project, and wanted to uninstall the custom Python 2.7 installation, so that I can start from scratch on a new installation of Python 3. This required some web-surfing, and some hours to figure out how to do it properly. After reading and deciphering some posts by others, I can now give an updated clean solution.
This assumes you have a good knowledge of shell / bash usage. This works for Python 2.7 installed by the user, but I am sure it works the same if you want to uninstall Python 3 from macOS Sierra too.
- Step 1: Manually remove Python 2.7 folder from Applications (drag to Trash).
- Step 2: Remove the Python 2.7 framework from /Library through the terminal: sudo rm -rf /Library/Frameworks/Python.framework
- Step 3: Clear python files from /usr/local/bin: sudo rm -rf /usr/local/bin/python*
- Step 4: Clear symbolic links to deleted Python files. If you have Homebrew installed already (highly recommended), then simply run brew doctor first, which will show you the broken symbolic links. Then just run brew prune to fix them (you can check it by running brew doctor again). If you don’t have Homebrew installed, then follow Step 3 here.
Now we are ready for a fresh Python install from scratch!
NOTE: After uninstallation, I do need to fix the system to call the default python version installed in macOS Sierra. Probably need to revise some path specifications. But I am more concerned with the new Python3 installation at this point :). See here for more on this.
CAUTION: Under no circumstances should you try to delete or touch anything in the /System or /usr/bin/python folders. This can cause your macOS to malfunction, your Macbook could self-destruct, and there is a possibility of an alien invasion as well. If you don’t believe me, just do a web search on why not to touch anything in the macOS /System folder.