title: Cannot "sudo pip uninstall" operation not permitted (/tmp) in OS X El Capitan
body: <p>Preface: My OS X Python installation is a <strong>mess</strong>. I started using the system Python way before I found out about Homebrew. And so I've been using <code>sudo pip install</code> since forever. I'm now trying to clean everything up and then install/link pip packages against Homebrew's Python.</p>
  
  <p>1) In many SO answers, people suggest doing: <code>pip freeze | xargs sudo pip uninstall -y</code> That doesn't work for me. I get a very long traceback. These are the most representative chunks of it:</p>
  
  <pre><code>~ $ pip freeze | xargs sudo pip uninstall -y
  You are using pip version 7.1.2, however version 8.0.2 is available.
  You should consider upgrading via the 'pip install --upgrade pip' command.
  The directory '/Users/smaniato/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
  Uninstalling altgraph-0.10.2:
  Exception:
  Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 211, in main
  [...]
  Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.py', '/tmp/pip-p8yIlU-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-p8yIlU-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.pyc', '/tmp/pip-p8yIlU-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.pyc',
  [...]
  "[Errno 1] Operation not permitted: '/tmp/pip-p8yIlU-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph'")]
  </code></pre>
  
  <p>where <code>altgraph</code> is just the first pip package in <code>pip list</code> (keep that in mind).</p>
  
  <p>2) I then tried <code>pip freeze | xargs sudo -H pip uninstall -y</code>, as the warning suggested, but that simply remove the warning. The error messages persisted.</p>
  
  <p>3) I also tried chown-ing any directories that raised complaints (e.g., <code>~/Library/Caches/pip</code> and some of its parents and children). For some reason, I cannot <code>chown</code> the most problematic directory, <code>/tmp</code>:</p>
  
  <pre><code>~ $ sudo chown -R ${USER} /tmp
  chown: /tmp: Operation not permitted
  </code></pre>
  
  <p>4) Finally, I tried manually uninstalling a package from <em>further down the list</em> and voila, I could easily do <code>sudo pip uninstall virtualenv</code> for example. Attempting to manually uninstall <code>altgraph</code> results in the same error above.</p>
  
  <p>Any ideas how to proceed? Remember, I don't care about any one package; I just want to nuke pip and start from scratch using Homebrew's Python. Thanks!</p>
  
  <p>Updates:</p>
  
  <ol>
  <li>Going down the list manually, the same thing happens with <code>bdist-mpkg-0.5.0</code></li>
  <li>A few more: <code>matplotlib</code>, <code>zope.interface</code>, <code>xattr</code>, <code>six</code>, <code>scipy</code>, <code>pytz</code>.</li>
  </ol>