How to Completely Uninstall Python on macOS

Problem:

  • You have an issue with a specific Python version (e.g. version 3.7).
  • You want to install differerent version (e.g. version 3.6).
  • You want to completely uninstall the current version before installing the new one.

Solution:

Assume the current version is 3.7, replace it with the version you installed (e.g. version 3.8).

Follow the 3 steps below.

1. Remove the third-party Python 3.7 framework

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

2. Remove the Python 3.7 applications directory

sudo rm -rf "/Applications/Python 3.7"

3. Remove the symbolic links, in /usr/local/bin, that point to this Python version. Ensure that the links exit using below command:

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

then run the following commands to remove all the links:

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

Installing a new version:

  1. Download a version from https://www.python.org/downloads/mac-osx/, double click the file and follow the instructions.
  2. Verify installation: python3 –version
  3. Install Homebrew from https://brew.sh
  4. Install virtualenv:
    pip3 install virtualenv
    pip3 install virtualenvwrapper
  5. Create and activate a virtual environment:
    cd /Users/admin/Downloads/training_model/model
    python3 -m virtualenv /Users/admin/Downloads/training_model/model
    source bin/activate

     

(Visited 17,645 times, 3 visits today)

Leave a Reply