Uninstalling Python on Mac OS X can be a bit tricky, especially when you have multiple versions installed. In this tutorial, we will walk through the steps to completely remove a third-party Python installation from your Mac.
Introduction
Mac OS X comes with a pre-installed version of Python, which is located in /System/Library
and /usr/bin
. However, if you have installed a third-party Python framework, such as those downloaded from the official Python website, you may want to remove it completely. This tutorial will guide you through the process of uninstalling a third-party Python installation.
Removing the Python Framework
To remove the Python framework, you need to delete the following directories and files:
/Library/Frameworks/Python.framework/Versions/2.7
: This is the main directory for the Python 2.7 framework./Applications/Python 2.7
: This is the applications directory for Python 2.7.
You can use the following commands to remove these directories:
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
Removing Symbolic Links
The Python installation may have created symbolic links in /usr/local/bin
that point to the removed framework. To remove these links, you can use the following command:
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm
This command lists all the links in /usr/local/bin
, filters out those that point to the removed framework, and then removes them.
Editing Shell Profile Files
If you have modified your shell profile files to include the removed Python framework in your PATH
environment variable, you need to edit these files to remove the reference. The following files may have been modified:
~/.bash_login
~/.bash_profile
~/.cshrc
~/.profile
~/.tcshrc
~/.zshrc
~/.zprofile
Open these files in a text editor and remove any lines that reference the removed Python framework.
Using pkgutil to Uninstall Packages
If you installed Python using a PKG installer, you can use the pkgutil
command to uninstall the packages. First, list all the packages installed on your system:
pkgutil --pkgs
Then, filter out the packages that are related to Python:
pkgutil --pkgs | grep org.python.Python
This will output a list of package IDs that you can use to uninstall the packages. For example:
pkgutil --unlink org.python.Python.PythonApplications-2.7
pkgutil --unlink org.python.Python.PythonDocumentation-2.7
pkgutil --unlink org.python.Python.PythonFramework-2.7
pkgutil --unlink org.python.Python.PythonProfileChanges-2.7
pkgutil --unlink org.python.Python.PythonUnixTools-2.7
Alternatively, you can use the following command to uninstall all the Python-related packages at once:
pkgutil --pkgs | grep org.python.Python | xargs -L1 pkgutil -f --unlink
Note that the --unlink
option is not available on Mac OS X Lion or later. In this case, you can use alternative methods to uninstall the packages.
Conclusion
Uninstalling Python on Mac OS X requires careful attention to detail to ensure that all related files and directories are removed completely. By following the steps outlined in this tutorial, you should be able to remove a third-party Python installation from your Mac.