How to fix pip error "Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')"?

Viewed 304

In a virtual environment I get the error

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

when I run commands like

python -m pip install --upgrade pip
python -m pip freeze

However, when I run the same command with pip it works, e.g.

pip install --upgrade pip
pip freeze

python is the same as python3, version is 3.8.12, I reinstalled pip using

pip install --force-reinstall pip

pip version is 21.3.1.

What else can I do so the python -m pip commands work again?

1 Answers

Well, the problem is that a version 60.3.0 is being used, which has a bug. But you cannot install a different version of setuptools, because you have already installed version 60.3.0.

Solution: Wait for version >60.3.0

On 7 Jan 2022 Version 60.3.1 has been released, which fixed the problem in the question.

Related