Guidelines for Removing Python from a Mac

Writers_App

No comments

Python is pre-installed on macOS, with the Apple-provided Python Framework located at /System/Library/Frameworks/Python.framework.

Several symbolic links can be found within the usr/bin/python directory.

Attempting to uninstall the version of Python pre-installed by Apple could lead to operating system instability.

If you’re looking to uninstall any third-party Python frameworks installed from python.org, this guide offers detailed steps to completely remove Python from your Mac.

Before we begin, it’s crucial to understand the multiple processes that occur during the Python installation.

  • A folder will be placed in the Applications directory, housing IDLE, PythonLauncher, and the Build Applet tool.
  • The framework will be installed in the /Library/Frameworks/Python.framework directory, which houses both the Python executable and various libraries.
  • Multiple symbolic links to the Python executable will be created in the /usr/local/bin directory..

To fully uninstall Python from your system, it is necessary to eliminate all these items.

Remember, two versions of Python, Python 2 and Python 3, are available. If both versions are installed and you wish to remove only one, detailed instructions for doing so can be found in the subsequent steps.

Step 1: Manually delete the Python directories located within the Applications folder.

In Finder, navigate to the Applications folder.

Transfer all installed Python directories to the Trash to uninstall them. Should you prefer to delete a specific version, only dispose of the file associated with that particular version.

how to uninstall Python on Mac

If the following dialog box gets prompted, please enter the password.

uninstall Python Mac

Next, go to the Trash directory.

Right-click on the folder and select Delete Immediately.

remove Python from Mac

Simply deleting Python folders does not fully remove Python from your system. For a complete uninstallation of Python, follow these steps.

Step 2: Delete the Python Framework from the /Library directory.

We will use the command line starting from this step.

Press command + space to bring up the Spotlight Search.

Search for Terminal and open it.

delete Python on Mac

In the terminal type the following command to remove all the Python Frameworks present in the /Library directory and hit enter.

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

how to remove Python from Mac

If prompted to enter the password, please do so.

If you would like to delete only a specific version of Python, please update your command as below.

Removing Python 2.7

Remove via Mac terminal

Removing Python 3.8

Remove via Mac terminal

Step 3: Delete Python symbolic links

Now that we deleted all python directories and files, there may be links in your system that may still be referencing the folders that we have already deleted. This step will ensure that all such links will be deleted.

There are two ways in which this step could be performed. Let’s look at both the ways in detail.

1st Method: Using Homebrew

We strongly advise installing Homebrew if it’s not already part of your setup. You can do so by executing the following command in the Terminal.

/bin/bash -c “$(curl -fsSL ​https://raw.githubusercontent.com/Homebrew/install/master/install.sh​)”

(Please refer to the Homebrew official site https://brew.sh​ for more information)

You can easily find broken symbolic links by running the command.

brew doctor

Remove via Mac terminal

The result will look like this (Please note that your result may look different)

Remove via Mac terminal

Run the command ‘brew cleanup’ as instructed to remove all broken symlinks.

2nd Method: Manual deletion

The symlinks referencing Python frameworks are in the /usr/local/bin directory. If you would like to see the broken symlinks, please use the following command.

ls -l /usr/local/bin | grep ‘../Library/Frameworks/Python.framework’

(The path ‘/Library/Frameworks/Python.framework’ should be replaced by what you chose in Step 2’)

Remove via Mac terminal

The result will show you all the links that are referencing the Python frameworks.

Remove via Mac terminal

To delete these broken symlinks, please use the following commands.

To enter into the directory

cd /usr/local/bin

Remove via Mac terminal

To delete the broken symlinks in the directory

ls -l /usr/local/bin | grep ‘../Library/Frameworks/Python.framework’ | awk ‘{print $9}’ | tr -d @ | xargs rm*

(Please keep in mind that the path ‘/Library/Frameworks/Python.framework’ should be changed according to the path you chose in Step 2.)

And there you go. Your system is now entirely purged of Python. You’re all set to either install a fresh version of Python or keep it as is.

Tags:

Share:

Related Post

Leave a Comment