Uninstalling python 3.x and reinstalling it from homebrew

I had already installed python3.8 using the installer from python.org. On the other hand, homebrew has installed python3.9 (which was probably needed to install some other package). But the path still points to the 3.8 version, and I wanted to get rid of this version — I like to keep my system clean, which is a kind of obsession rather than necessity. Unfortunately, python.org does not provide any uninstaller –I wonder why. So I had to do it manually.

The documentation from python.org gives me the required information about the python installation directories as follows:

  • Python 3.8 folder in your Applications folder. In here you find IDLE, the development environment that is a standard part of official Python distributions; and PythonLauncher, which handles double-clicking Python scripts from the Finder.
  • A framework /Library/Frameworks/Python.framework, which includes the Python executable and libraries. The installer adds this location to your shell path. To uninstall MacPython, you can simply remove these three things. A symlink to the Python executable is placed in /usr/local/bin/.

However, I wanted to make sure before deleting the files. Therefore, I have performed the following steps:

$ ls -l  /usr/local/bin/python*
lrwxr-xr-x 1 root wheel 69 Sep 8 11:16 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x 1 root wheel 76 Sep 8 11:16 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x 1 root wheel 71 Sep 8 11:16 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x 1 root wheel 78 Sep 8 11:16 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config

shows that python3.8 has been installed in the directory:
“/Library/Frameworks/Python.framework/Versions/3.8/”.

Next

$ cd /usr/local/bin
$ ls -l |grep /Library/Frameworks/Python.framework/
lrwxr-xr-x  1 root    wheel        66 Sep  8 11:16 2to3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/2to3
lrwxr-xr-x  1 root    wheel        70 Sep  8 11:16 2to3-3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/2to3-3.8
lrwxrwxr-x  1 root    admin        78 Sep  8 11:17 easy_install-3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/easy_install-3.8
lrwxr-xr-x  1 root    wheel        67 Sep  8 11:16 idle3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/idle3
lrwxr-xr-x  1 root    wheel        69 Sep  8 11:16 idle3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/idle3.8
lrwxrwxr-x  1 root    admin        66 Sep  8 11:17 pip3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/pip3
lrwxrwxr-x  1 root    admin        68 Sep  8 11:17 pip3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/pip3.8
lrwxr-xr-x  1 root    wheel        68 Sep  8 11:16 pydoc3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/pydoc3
lrwxr-xr-x  1 root    wheel        70 Sep  8 11:16 pydoc3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/pydoc3.8
lrwxr-xr-x  1 root    wheel        69 Sep  8 11:16 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x  1 root    wheel        76 Sep  8 11:16 python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x  1 root    wheel        71 Sep  8 11:16 python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x  1 root    wheel        78 Sep  8 11:16 python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config

shows all the symlinks from the directory “/usr/local/bin” to the directory “/Library/Frameworks/Python.framework/”. It also shows that all the links are only to the subdirectory “/Versions/3.8” indicating that, most likely, no other versions of python are installed there.

To double-check (I don’t want to end up deleting something crucial):

$ cd
$ ls -l /Library/Frameworks/Python.framework/
total 0
lrwxr-xr-x  1 root  wheel   24 Sep  8 11:16 Headers -> Versions/Current/Headers
lrwxr-xr-x  1 root  wheel   23 Sep  8 11:16 Python -> Versions/Current/Python
lrwxr-xr-x  1 root  wheel   26 Sep  8 11:16 Resources -> Versions/Current/Resources
drwxrwxr-x  4 root  wheel  128 Sep  8 11:16 Versions
$ ls -l /Library/Frameworks/Python.framework/Versions/
total 0
drwxrwxr-x  11 root  admin  352 Sep  8 11:16 3.8
lrwxr-xr-x   1 root  wheel    3 Sep  8 11:16 Current -> 3.8

Clearly, 3.8 is the only version installed in the directory “/Library/Frameworks/Python.framework/”. So without hesitation, I remove the whole directory.

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

To remove the symlinks from “/usr/local/bin”

$ cd /usr/local/bin/
$ sudo rm -f 2to3* easy_install-3.8 idle3* pip3* pydoc3* python3*

Finally,

$ sudo rm -rf /Applications/Python\ 3.8/

Now my system is free of python3.8. Now to install python3.9

$ brew install python@3.9