我无法通过pip卸载软件包(Python)

时间:2017-08-02 16:54:34

标签: python pip

当我在装有MacOS Sierra 10.12.6的计算机上运行“pip list”时,终端上会列出一些软件包:

IST01-12345:~ myMac$ sudo pip list
altgraph (0.10.2)
bdist-mpkg (0.5.0)
bonjour-py (0.3)
macholib (1.5.1)
matplotlib (1.3.1)
modulegraph (0.10.4)
numpy (1.8.0rc1)
pip (9.0.1)
py2app (0.7.3)
pyobjc-core (2.5.1)
pyobjc-framework-Accounts (2.5.1)
pyobjc-framework-AddressBook (2.5.1)
pyobjc-framework-AppleScriptKit (2.5.1)
pyobjc-framework-AppleScriptObjC (2.5.1)
pyobjc-framework-Automator (2.5.1)
pyobjc-framework-CFNetwork (2.5.1)
pyobjc-framework-Cocoa (2.5.1)
pyobjc-framework-Collaboration (2.5.1)
pyobjc-framework-CoreData (2.5.1)
pyobjc-framework-CoreLocation (2.5.1)
pyobjc-framework-CoreText (2.5.1)
pyobjc-framework-DictionaryServices (2.5.1)
pyobjc-framework-EventKit (2.5.1)
pyobjc-framework-ExceptionHandling (2.5.1)
pyobjc-framework-FSEvents (2.5.1)
pyobjc-framework-InputMethodKit (2.5.1)
pyobjc-framework-InstallerPlugins (2.5.1)
pyobjc-framework-InstantMessage (2.5.1)
pyobjc-framework-LatentSemanticMapping (2.5.1)
pyobjc-framework-LaunchServices (2.5.1)
pyobjc-framework-Message (2.5.1)
pyobjc-framework-OpenDirectory (2.5.1)
pyobjc-framework-PreferencePanes (2.5.1)
pyobjc-framework-PubSub (2.5.1)
pyobjc-framework-QTKit (2.5.1)
pyobjc-framework-Quartz (2.5.1)
pyobjc-framework-ScreenSaver (2.5.1)
pyobjc-framework-ScriptingBridge (2.5.1)
pyobjc-framework-SearchKit (2.5.1)
pyobjc-framework-ServiceManagement (2.5.1)
pyobjc-framework-Social (2.5.1)
pyobjc-framework-SyncServices (2.5.1)
pyobjc-framework-SystemConfiguration (2.5.1)
pyobjc-framework-WebKit (2.5.1)
pyOpenSSL (0.13.1)
pyparsing (2.0.1)
python-dateutil (1.5)
pytz (2013.7)
scipy (0.13.0b1)
setuptools (18.5)
six (1.4.1)
virtualenv (15.1.0)
xattr (0.6.4)
zope.interface (4.1.1)

但是,当我卸载这些软件包中的一个( altgraph )时,出现如下错误:

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/uninstall.py", line 76, in run
    requirement_set.uninstall(auto_confirm=options.yes)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 346, in uninstall
    req.uninstall(auto_confirm=auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-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-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Dot.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/Graph.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphAlgo.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphStat.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/GraphUtil.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.py', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.py', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.pyc', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph/ObjectGraph.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph', '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph', "[Errno 1] Operation not permitted: '/tmp/pip-BQys7K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/altgraph'")]

我还检查了一些路径和版本:

IST01-12345:~ myMac$ which python && python --version
/usr/bin/python
Python 2.7.10
IST01-12345:~ myMac$ which pip && pip --version
/usr/local/bin/pip
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
IST01-12345:~ myMac$ which easy_install && easy_install --version
/usr/bin/easy_install
setuptools 18.5 from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (Python 2.7)
IST01-12345:~ myMac$ which pytz && pytz --version
IST01-12345:~ myMac$ which scipy && scipy --version
IST01-12345:~ myMac$ which altgraph && altgraph --version

虽然列表中显示“pytz”,“scipy”和“altgraph”,但我找不到它们的路径和版本。你怎么看?如何卸载它们,或者如何从此列表中删除这些包?在/ usr / bin下使用python而不是python / usr / local / bin会出现这个问题吗?

1 个答案:

答案 0 :(得分:2)

安全问题?如果是这样,请以超级用户身份运行pip:

sudo pip uninstall <packagename>

Python安装的一个问题是通常存在多个问题,并且它们在放置文件的位置上存在很大差异,尤其是它们。横跨Python 2和Python 3划分,并有几个主要的Python构建源(Apple默认,Homebrew,Python.org构建,ActiveState,Enthought Canopy,...)。其中一些安装使用Apple位置指南,一些使用Unix约定,一些使用其他Unix约定,一些使用用户空间,......基本上,它只是一团糟,只知道文件的存在位置。只有几个可能的地方:

/Library/Python/2.7/site-packages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages    
/System/Library/Frameworks/Python.framework/Versions/2.7/

我经常发现我必须cd到这些文件位置,查找libsite-packages目录,并使用rm(通常{{ 1}})真正删除一些模块遗迹,尤其是如果混合使用sudo rm -rf <file-or-directory>easy_installpip install安装技术。

python setup.py install/Library前缀表示您在官方位置使用/取决于Apple安装的Python。所以必须/System/Library授权。可能需要sudo / cd路线。