在 Mac OS Catalina 上卸载所有 `pip` 包

问题描述

尝试卸载 Mac 上的所有 pippip3 软件包,但遇到以下错误,这些错误主要与 OSError: [Errno 30] Read-only file system:[Errno 1] Operation not permitted: 相关。我已经试过了:

  • 使用 csrutil disable 并在禁用 csrutil 时运行卸载命令
  • 在禁用 sudo -H 时尝试 csrutil 进行卸载

这些是错误

第一:SIP 状态以及 pippip3 信息

$ csrutil status
System Integrity Protection status: disabled.
$ pip list
zsh: command not found: pip
$ python -m pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package                                Version 
-------------------------------------- --------
altgraph                               0.10.2  
asn1crypto                             0.24.0  
backports-abc                          0.5     
bdist-mpkg                             0.5.0   
bonjour-py                             0.3     
cffi                                   1.12.2  
...
...
xattr                                  0.6.4   
$ python3 -m pip list
Package    Version
---------- -------
pip        19.2.3 
setuptools 50.3.2 
wheel      0.35.1 

第二:尝试使用 pip

卸载所有 python -m pip freeze | xargs python -m pip uninstall -y 软件包
$ python -m pip freeze | xargs python -m pip uninstall -y
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Uninstalling pyobjc-framework-AppleScriptObjC-2.5.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/cli/base_command.py",line 176,in main
    status = self.run(options,args)
  File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/commands/uninstall.py",line 75,in run
    auto_confirm=options.yes,verbose=self.verbosity > 0,File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/req/req_install.py",line 823,in uninstall
    uninstalled_pathset.remove(auto_confirm,verbose)
  File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/req/req_uninstall.py",line 268,in remove
    renames(path,new_path)
  File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/utils/misc.py",line 303,in renames
    shutil.move(old,new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py",line 322,in move
    copytree(src,real_dst,symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py",line 231,in copytree
    raise Error,errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_Metadata.pyc','/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/_Metadata.pyc',"[Errno 1] Operation not permitted: '/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/_Metadata.pyc'"),('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_Metadata.py','/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/_Metadata.py',"[Errno 1] Operation not permitted: '/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/_Metadata.py'"),('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.py','/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/__init__.py',"[Errno 1] Operation not permitted: '/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/__init__.py'"),('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.pyc','/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/__init__.pyc',"[Errno 1] Operation not permitted: '/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC/__init__.pyc'"),('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC','/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC',"[Errno 1] Operation not permitted: '/private/var/folders/74/01qhmy3s3qg_fwctkdf6mrvh0000gn/T/pip-temp-Udv2QQ/AppleScriptObjC'")]

使用 sudo python -m pip freeze | xargs sudo python -m pip uninstall -ysudo -H python -m pip freeze | xargs sudo -H python -m pip uninstall -y 重试

$ sudo python -m pip freeze | xargs sudo python -m pip uninstall -y
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
The directory '/Users/.../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 pyobjc-framework-AppleScriptObjC-2.5.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg/pip/_internal/cli/base_command.py",line 323,in move
    rmtree(src)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py",line 275,in rmtree
    onerror(os.remove,fullname,sys.exc_info())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py",line 273,in rmtree
    os.remove(fullname)
OSError: [Errno 30] Read-only file system: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_Metadata.pyc'
$ sudo -H python -m pip freeze | xargs sudo -H python -m pip uninstall -y
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,in rmtree
    os.remove(fullname)
OSError: [Errno 30] Read-only file system: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_Metadata.pyc'

此处在 Apple Stack 上对此进行了简要讨论:https://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-os-x-el-capitan-upgrade/209583 但重点是安装问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)