在 macOS 中重新安装 pip2?

Posted

技术标签:

【中文标题】在 macOS 中重新安装 pip2?【英文标题】:Reinstalling pip2 in macOS? 【发布时间】:2021-05-11 09:17:07 【问题描述】:

% pip2

Traceback (most recent call last):
  File "/usr/local/bin/pip2", line 11, in <module>
    load_entry_point('pip==21.0.1', 'console_scripts', 'pip2')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2434, in load
    return self.resolve()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2440, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/pip-21.0.1-py2.7.egg/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: exc")

$Python2

%python2

WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Dec 21 2020, 23:00:36) 
[GCC Apple LLVM 12.0.0 (clang-1200.0.30.4) [+internal-os, ptrauth-isa=sign+stri on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Python2 工作正常,但 pip2 坏了,我无法安装任何软件包。如何重新安装 pip 以安装软​​件包?

【问题讨论】:

【参考方案1】:

您似乎正在尝试使用 pip 21 版,因此值得注意的是,pip 在 2021 年 1 月取消了对 Python 2 的支持,因此 Pip 20.3 版是支持 Python 2.7 的最后一个版本。

这是来自get-pip.py 的弃用通知:

弃用:Python 2.7 已于 2020 年 1 月 1 日结束其生命周期。请升级您的 Python,因为不再维护 Python 2.7。 pip 21.0 将于 2021 年 1 月停止对 Python 2.7 的支持。有关 pip 中 Python 2 支持的更多详细信息,请访问https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 将不再支持此功能。

话虽如此,请参阅 pip no longer working after update error 'module' object is not callable 或 Can I force pip to reinstall the current version? 以重新安装 pip。

如果你卸载了 pip,你仍然可以使用 Python 2.7 版本的get-pip.py 来安装它。

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2 get-pip.py

【讨论】:

curl https://bootstrap.pypa.io/2.7/get-pip.py -o get-pip.py 不再存在 - 404

以上是关于在 macOS 中重新安装 pip2?的主要内容,如果未能解决你的问题,请参考以下文章

如何抹掉 Mac 并重新安装 macOS?

如何在macos上完全卸载flutter并以正确的方式重新安装?

sh 在macOS Mojave上重新安装Brew的XCode命令行工具

如何在MacOS Sierra(10.x)上完全删除并重新安装PIP?

macOS系统抹盘恢复(准备安装时发生错误,请尝试重新运行此应用程序)

完全重新安装 Xcode 9