How to clean pip installed packages on MacOSX?

时间:2016-04-15 11:15:43

标签: python macos pip

I try to remove all pip installed packages from MacOSX. 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: mdroe@stsci.edu
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

1 个答案:

答案 0 :(得分:0)

我假设matplotlib在您运行时仍显示

$ pip freeze

我对OSX环境并不熟悉,但我会尝试尽可能地从Linux / GNU环境中进行调整。首先,您是否可以使用以下命令重新安装matplotlib:

$ pip install pysqlite

如果pip假定它已经安装

,它应该返回类似的东西
 Requirement already satisfied (use --upgrade to upgrade): matplotlib in PATH

使用此返回的路径,转到PATH/dist-packages/matlibplot*.egg/(或在python路径中存储鸡蛋的任何其他位置)并查找installed-files.txt文件。如果它不存在,则pip无法卸载软件包。

因此,手动替代方法是删除该egg路径中的所有文件,并且您将删除matplotlib。您可能还需要编辑easy-install.*目录中的dist-packages文件并从中删除matplotlib条目,以便pip freeze命令停止显示它。