54

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?

3
  • 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
    Commented Apr 25, 2022 at 20:24
  • 3
    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. Commented Apr 25, 2022 at 20:34
  • 1
    I suspect you aren't actually using Python 3.8 to create the virtual environment.
    – chepner
    Commented Apr 25, 2022 at 20:42

5 Answers 5

85

⚠️ WARNING: macOS comes with a system Python installation in /usr/bin/python3 that should NOT be removed as it's required for system functionality. Only remove Python versions you've manually installed.

Please read the end of 5.1.1 for official insight: https://docs.python.org/3/using/mac.html#installation-steps

Legacy Python

The previous edit for this question suggested removing /Library/Frameworks/Python.framework/Versions/2.x/bin/python as a way of completely removing Python. This flexibility has since changed with newer macOS updates.

Identify Your Python Installations

Before removing anything, determine which Python installations exist and where they're located:

# List all Python installations
which -a python python3

# Check Python versions
python3 --version

# Find installation locations
ls -l /opt/homebrew/bin/python*
ls -l /usr/local/bin/python*
ls -l /usr/bin/python*

For Homebrew Python

# Uninstall Python
brew uninstall [email protected]
# Remove orphaned files
brew cleanup
# List any broken symlinks, etc.
brew doctor

For Python.org installer

# Remove the application
sudo rm -rf /Applications/Python\ 3.x

# Check for framework files
ls -la /Library/Frameworks/Python.framework/Versions/
# If found, remove the specific version
sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.x

# Check for and remove symbolic links
# For Intel Macs:
cd /usr/local/bin
ls -l | grep '../Library/Frameworks/Python.framework/Versions/3.x' | awk '{print $9}' | xargs rm -f
# For Apple Silicon:
cd /usr/local/bin
ls -l | grep '../Library/Frameworks/Python.framework/Versions/3.x' | awk '{print $9}' | xargs rm -f

# Check for user-specific packages
ls -l ~/Library/Python/
# Remove if needed
rm -rf ~/Library/Python/3.x/

For pyenv-managed Python

# List all installed Python versions
pyenv versions

# Show the current active version
pyenv version

# Uninstall a specific version
pyenv uninstall 3.x.y

# Check pyenv installation location
ls -la ~/.pyenv/versions/

# Remove pyenv shims and rehash
pyenv rehash

# If you want to completely remove pyenv itself
# For Homebrew installation:
brew uninstall pyenv
# For manual installation:
rm -rf ~/.pyenv
# Don't forget to remove pyenv initialization from your shell profile
# (.bash_profile, .zshrc, etc.)

Clean Up Remaining Files

# Remove Python cache files
find ~/ -name "__pycache__" -type d -exec rm -rf {} +
find ~/ -name "*.pyc" -delete

# Check for any remaining Python-related directories
ls -la ~/Library/Application\ Support/ | grep -i python
ls -la ~/Library/Caches/ | grep -i python
9
  • 1
    For the given command to list broken symbolic links, on a macOS I had to replace the smart quotes with straight quotes. ''
    – mcwizard
    Commented Oct 31, 2022 at 0:42
  • 1
    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
    Commented Oct 31, 2022 at 0:44
  • 1
    None of these answers accounts for the fact that your PATH variable is impacted. In my case, using zsh, I had to remove a line from my .zprofile. Note this means you have to restart your terminal entirely afterwards.
    – Jesse H.
    Commented Jun 10, 2024 at 20:59
  • 1
    @mfaani if you installed with homebrew then the best option is likely to just uninstall with homebrew, like brew uninstall python
    – Brian
    Commented Mar 27 at 2:34
  • 1
    The files in ~/Library/Python seems to come from the systems python (/usr/bin/python3). I would leave this untouched though it's probably not necessary. Also this solution states Python from python.org installs symlinks into /opt/homebrew/bin for arm64 machines. This is not true. python.org installers always put symlinks into /usr/local/bin. Aside from that thanks for this complete paths :). This should exists for every macOS installer.
    – gernophil
    Commented May 24 at 20:19
58
# 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
3
  • Just in case someone went through the same, it worked for me when I used the two-number format, as in, "3.12" instead of the three-number, like "3.12.0".
    – 101is5
    Commented Nov 9, 2023 at 22:43
  • 1
    does it matter if I installed it using homebrew or installed it directly?
    – mfaani
    Commented Nov 29, 2023 at 11:43
  • I do what you describe but when I write the command 'python3.10' it still keeps opening the python terminal. any other suggestions?
    – csymvoul
    Commented Dec 10, 2024 at 9:26
5

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.

1
  • 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. Commented Aug 23, 2023 at 18:00
1

I was having problems uninstalling / removing [email protected]

Turns out I had used Homebrew to install it. Used: brew uninstall [email protected]

Worked like a charm.

0

If your version of Python was deployed, you'll also want to remove the receipt with pkgutil or else you'll run into issues trying to redeploy it in the future.

Grab the identifier from the installed package;

pkgutil --packages | grep Python

You'll be after these four. I'll be basing this on Python 3.12;

org.python.Python.PythonFramework-3.12
org.python.Python.PythonDocumentation-3.12
org.python.Python.PythonApplications-3.12
org.python.Python.PythonUnixTools-3.12

Then forget the receipts;

pkgutil --forget org.python.Python.PythonFramework-${PYTHON_VERSION_NUMBER}
pkgutil --forget org.python.Python.PythonDocumentation-${PYTHON_VERSION_NUMBER}
pkgutil --forget org.python.Python.PythonApplications-${PYTHON_VERSION_NUMBER}
pkgutil --forget org.python.Python.PythonUnixTools-${PYTHON_VERSION_NUMBER}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.