pypa / pip

The Python package installer

Home Page:https://pip.pypa.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misleading remedy for missing RECORD file with --force-reinstall

thegamecracks opened this issue · comments

Description

I was doing a bit of looking around to figure out how --force-reinstall was handled, and I found this code snippet:

msg = f"Cannot uninstall {dist}, RECORD file not found."
installer = dist.installer
if not installer or installer == "pip":
dep = f"{dist.raw_name}=={dist.version}"
msg += (
" You might be able to recover from this via: "
f"'pip install --force-reinstall --no-deps {dep}'."
)

It says that in the event of RECORD not being found, the package should be re-installed using --force-reinstall. However, I couldn't figure out how --force-reinstall would cause pip to skip the uninstallation step where it would fail. As it turns out, testing the suggested instructions resulted in pip failing to uninstall the package.

Expected behavior

I think instead of --force-reinstall, pip should suggest the --ignore-installed option so that it won't try to uninstall the package and lead to the same error message.

pip version

24.0

Python version

3.11.9

OS

Windows 11

How to Reproduce

  1. Go to the site-packages directory, pick a package, and manually remove the RECORD file from its .dist-info directory.
  2. Attempt to uninstall that package normally, i.e. pip uninstall pkg.
  3. Follow the suggested command to reinstall the package.

Output

$ pip uninstall tzdata
Found existing installation: tzdata 2024.1
ERROR: Cannot uninstall tzdata 2024.1, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps tzdata==2024.1'.
$ pip install --force-reinstall --no-deps tzdata==2024.1
Collecting tzdata==2024.1
  Using cached tzdata-2024.1-py2.py3-none-any.whl.metadata (1.4 kB)
Using cached tzdata-2024.1-py2.py3-none-any.whl (345 kB)
Installing collected packages: tzdata
  Attempting uninstall: tzdata
    Found existing installation: tzdata 2024.1
ERROR: Cannot uninstall tzdata 2024.1, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps tzdata==2024.1'.

Code of Conduct