Better error message for missing RECORD file
See original GitHub issueWhat’s the problem this feature will solve? According to PEP 627, the RECORD file is now optional and its absence indicates that a package should not be uninstalled/upgraded by pip or another tool that relies on its content (see the last paragraph in docs). In Fedora, when you install an RPM package without .dist-info/RECORD file and then you try to uninstall it via pip, you’ll get a traceback like this:
# pip uninstall django
Found existing installation: Django 3.0.7
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/usr/lib/python3.9/site-packages/pip/_internal/commands/uninstall.py", line 89, in run
uninstall_pathset = req.uninstall(
File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 685, in uninstall
uninstalled_pathset = UninstallPathSet.from_dist(dist)
File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 535, in from_dist
for path in uninstallation_paths(dist):
File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 67, in unique
for item in fn(*args, **kw):
File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 85, in uninstallation_paths
r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD')))
File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1432, in get_metadata_lines
return yield_lines(self.get_metadata(name))
File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1420, in get_metadata
value = self._get(path)
File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1616, in _get
with open(path, 'rb') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/python3.9/site-packages/Django-3.0.7.dist-info/RECORD'
Describe the solution you’d like
It would be nice to produce a better error message for cases like the one described above. It’d be also nice to use .dist-info/INSTALLER
file (if exists) to indicate which tool a user should use to work with the package. Note that the INSTALLER file is also optional according to the PEP.
Additional context PEP 627: https://www.python.org/dev/peps/pep-0627/ Related to: https://github.com/pypa/pip/issues/8156 Packaging docs: https://packaging.python.org/specifications/recording-installed-packages/
Cc: @hroncok
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Shouldn’t refusing to uninstall/upgrade a package with no
RECORD
be done in pip? I thinkpkg_resources.get_metadata_lines
is very correct to reportFileNotFoundError
if the file is not found.Here: https://github.com/pypa/pip/pull/9949