How to fully uninstall Python 3 on macOS Catalina?

How can I completely uninstall Python 3 from macOS after running brew uninstall Python? I used the command brew uninstall python3 on macOS Catalina 10.15.3, but it still shows up when I check the version and path:

which python3
/usr/bin/python3

python3 -V
Python 3.7.3

Despite uninstalling it with brew uninstall Python, the version remains, and the python3 command still points to /usr/bin/python3. Additionally, I found this path when listing files in /usr/bin:

-rwxr-xr-x     1 root   wheel    31K Jan 23 16:58 python3

When I attempt to remove it using sudo rm -f /usr/bin/python3, I get the error: “Operation not permitted.”

I also see that the Python version from Xcode appears when I run python3 -bla. How can I completely delete this version of Python 3 and reinstall it using brew?

Alright, so if you want to fully uninstall Python 3 from macOS Catalina, here’s where you start. The trick is dealing with System Integrity Protection (SIP), which is a security feature that prevents modifying critical system files. To get rid of Python 3 from /usr/bin, you need to temporarily disable SIP. Here’s how you can do that:

  1. Restart your Mac and hold Cmd + R to boot into Recovery Mode.
  2. Open Terminal from the Utilities menu.
  3. Type in the command: csrutil disable and hit Enter.
  4. Restart your Mac normally.

Now, you’re free to delete Python 3 from the system with the command:

sudo rm -f /usr/bin/python3

Once you’ve done that, I recommend re-enabling SIP for security. You can do that by following the same steps, but this time run csrutil enable in Recovery Mode. This should clear up the system-installed Python 3.

Great, now that you’ve cleared out the system version, there’s still a chance Python 3 is being managed through Xcode—macOS often uses it. So, here’s an additional step that could save you some hassle:

  1. Open up Terminal and run the command to check Xcode’s installation path:
xcode-select --print-path
  1. If you see that Xcode’s Python version is present, you can unlink or remove it by running this:
sudo rm -f /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework

At this point, you might want to make sure you’re using a clean installation, so go ahead and run the following to reinstall Python via brew:

brew install python

This will get you a fresh, correct version of Python 3.

Perfect, we’ve cleared out the system and Xcode versions, but if you’re still having trouble with Python 3 lingering around, there’s a good fallback. Sometimes, it’s all about ensuring there are no conflicting versions installed via brew. Here’s a neat way to handle it:

  1. First, use brew to uninstall Python 3:
brew uninstall python
  1. Then, double-check that no versions of Python are still hanging around by running:
brew list | grep python
  1. If you see anything remaining, go ahead and remove those. Afterward, reinstall Python cleanly via brew:
brew install python

Finally, ensure the right version is being used by checking the path with:

which python3

This should point to the correct directory, typically /usr/local/bin/python3. That should do the trick!