21

I installed Python 3 on Mac and installed some packages as well. But then I see AWS lamda does not support Python 3 so I decided to downgrade. I removed Python3 folder in Applications and cleared the trash. But still I see a folder named 3 in /Library/Frameworks/Python.framework/Versions which is causing problems, such as this:

  $ python3 -m pip install virtualenv
 Requirement already satisfied: virtualenv in      /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (20.14.1)
 Requirement already satisfied: platformdirs<3,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from virtualenv) (2.5.2) 

So my question is how do I completely uninstall python 3 from my Mac?

Angus
  • 70
  • 6
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • 1
    Why uninstall it? Lambda will support it at *some* point, and you can install multiple versions of Python side-by-side until then. – chepner Apr 25 '22 at 20:24
  • 2
    Ok, but because I am learning lambda from scratch I just wanted to be safe and not waste time in debugging issues caused by configurations. For instance, when I am installing virtualenv after installing python 3.8, it is finding site-packages in 3.10 folder in library(when 3.10 was supposedly uninstalled). Not sure if something unpredictable happens. – Deepak Sharma Apr 25 '22 at 20:34
  • 1
    I suspect you aren't actually using Python 3.8 to create the virtual environment. – chepner Apr 25 '22 at 20:42

3 Answers3

23

Removing the app does not completely uninstall that version of Python. You will need to remove the framework directories and their symbolic links.

Deleting the frameworks

sudo rm -rf /Library/Frameworks/Python.framework/Versions/[version number] replacing [version number] with 3.10 in your case.

Removing symbolic links

To list the broken symbolic links.

ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/[version number]'

And to remove these links:

cd /usr/local/bin

ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/[version number]' | awk '{print $9}' | tr -d @ | xargs rm*

As always, please be wary of copying these commands. Please make sure the directories in the inputs are actual working directories before you execute anything.

The general idea in the end is to remove the folders and symlinks, and you're good to go.

Here is another response addressing this process: How to uninstall Python 2.7 on a Mac OS X 10.6.4?

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
zayadur
  • 541
  • 4
  • 9
  • For the given command to list broken symbolic links, on a macOS I had to replace the smart quotes with straight quotes. '' – mcwizard Oct 31 '22 at 00:42
  • On macOS, when determining version: % Python3 --version response was Python 3.8.6 but the directory is 3.8 so slight amplification of the answer, you may not want to put the full, responded version number in, use the directory name in which is likely to be the minor version, slightly truncated version. – mcwizard Oct 31 '22 at 00:44
16
# The version of Python that you want to delete
python_version_number=3.10
sudo rm -rf /Library/Frameworks/Python.framework/Versions/${python_version_number}/
sudo rm -rf "/Applications/Python ${python_version_number}/"
cd /usr/local/bin && ls -l | grep "/Library/Frameworks/Python.framework/Versions/${python_version_number}" | awk '{print $9}' | sudo xargs rm
h2appy
  • 199
  • 1
  • 4
1

The other answers here may become outdated if the Python installer changes what it's installed and where. However, a more general solution like this one that explains how to remove all the contents of a .pkg file from your mac will clean up the files included with the installer, and will be resilient to most installer changes in the future.

Glyph
  • 31,152
  • 11
  • 87
  • 129
  • My old install (3.8) didn't support this, but the newer one (3.11) did. Not sure when they implemented a proper package. Could possibly be an option in the installer I missed in the earlier version. – Gringo Suave Aug 23 '23 at 18:00