How to clean pip installed packages on MacOSX?

I try to remove all pip installed packages from MacOSX. I'm doing it to ensure I'm using homebrew pip from now on (to avoid problems with SIP).

Following zsh loop removed most of them, but some resists.

for i ($(pip freeze )) {pip uninstall -y $i}

For example matlibplot hasn't been removed. When I try to run uninstall it find matplotlib, print related paths, but fails.

pip uninstall matplotlib
Uninstalling matplotlib-1.3.1:
 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib
 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib-1.3.1-py2.7.egg-info
 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pylab.py
 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pylab.pyc
Proceed (y/n)?

I got following very long error message. It seems that files cannot be removed. Error sample:

error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py', '/tmp/pip-PK6UUB-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-PK6UUB-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py'"),

What should I do?

To make clear, commands are run from root account. Pip can find package metadata:

pip show matplotlib
---
Metadata-Version: 1.1
Name: matplotlib
Version: 1.3.1
Summary: Python plotting package
Home-page: http://matplotlib.org 
Author: John D. Hunter, Michael Droettboom
Author-email: [email protected]
License: BSD
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires: numpy, python-dateutil, tornado, pyparsing, nose
Classifiers:
  Development Status :: 5 - Production/Stable
  Intended Audience :: Science/Research
  License :: OSI Approved :: Python Software Foundation License
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 3
  Topic :: Scientific/Engineering :: Visualization

Looking at similar questions (e.g. discussion below this one) I decided temporary disable SIP. Clean pip and enable SIP again.

  • To disable SIP I followed this instruction: https://www.macbartender.com/system-item-setup/

  • After that I ran

    for i ($(pip freeze )) {pip uninstall -y $i}
    
  • Checked that everything pip related is removed

  • Restarted OS again and enable SIP using again https://www.macbartender.com/system-item-setup/