Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')

Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')

长话短说,我做了一个 pip 升级和一个命令,告诉它在一个文件中安装一堆依赖项,现在当我尝试用 pip 做任何事情时,它正在抛出我

例如,运行

py -m pip -V

投掷

Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')

连同涉及我尝试调用我的 python 3.8 点的任何其他内容。

运行

py -m ensurepip

告诉我 pip 实际上已安装。

Requirement already satisfied: setuptools in c:\program files (x86)\python38-32\lib\site-packages (60.3.0)
Requirement already satisfied: pip in c:\program files (x86)\python38-32\lib\site-packages (21.3.1)

其中涵盖了 pip 未安装,模块未安装的情况,类似的问题似乎可以解决。那么,有没有人知道发生了什么以及如何让 pip 作为一个模块再次开始工作?

This was a bug with setuptools. Version 60.3.1 has now been released 修复它。


以前版本 60.3.0 was yanked from PyPI, which I believe resolves the issue once you run another upgrade. (I wasn't hit by it myself.) If not, GitHub user ferrants suggested this workaround:

python3 -m pip install --upgrade setuptools==60.2.0

谢谢,我需要用 pip3 install --upgrade setuptools==60.2.0