Python
Development Environment
Delete
Mac

How to completely delete Python in Mac

If you installed Python using the installer file provided by the Python official website (opens in a new tab), be sure to delete all related files in the three paths to completely remove the Python executable. Otherwise, it may conflict with files installed by other distributions such as Anaconda or methods such as HomeBrew.

So let's proceed with the complete Python uninstall. The delete command should always be used with caution, so please read carefully and proceed.

1. Delete the installation directory

First, delete the installation path directory itself, which we found in the Installation Path (Mac).

Your version may be different, so be sure to verify the folder name with the command mentioned in the above post before proceeding.

sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.11

2. Delete the shortcuts

Since the actual installation directory has been deleted, the shortcuts have become meaningless. We need to delete them all.

Before deleting, check the files you want to delete to make sure you don't delete other files as well. Make sure to check the version.

ls -l /usr/local/bin | grep '../../../Library/Frameworks/Python.framework/Versions/3.11'

The result of the execution:

Python-related shortcuts

If you look at the list output by the command, these are all Python-related files that you installed. Execute the command below to remove them.

cd /usr/local/bin && ls -l | grep '../../../Library/Frameworks/Python.framework/Versions/3.11' | awk '{print $9}' | tr -d @ | xargs rm

In some cases, you may get an error like the one below, and the removal will not proceed.

Python removal error

The above error occurs because you do not have permission to delete the file and directory.

To fix this, type the following command. We have obtained administrator privileges with the sudo keyword and applied it to the rm delete command.

cd /usr/local/bin && ls -l | grep '../../../Library/Frameworks/Python.framework/Versions/3.11' | awk '{print $9}' | tr -d @ | xargs sudo rm​

3. Delete the application

Delete the files in the applications folder as well. Again, be sure to rename the Python 3.xx directory to the appropriate version.

sudo rm -rf "/Applications/Python 3.11/"

4. Confirm deletion

If you type in the Python REPL or the Python version check command, you'll see that you're back to the default built-in Python version.

Check Python version

copyright for Python delete

© 2023 All rights reserved.