Skip to content

Warn on file conflicts when installing packages - #14249

Open
sepehr-rs wants to merge 1 commit into
pypa:mainfrom
sepehr-rs:fix-4625
Open

Warn on file conflicts when installing packages#14249
sepehr-rs wants to merge 1 commit into
pypa:mainfrom
sepehr-rs:fix-4625

Conversation

@sepehr-rs

@sepehr-rs sepehr-rs commented Aug 13, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Fixes #4625.

The approach taken here is to iterate over the installed distributions and track each RECORD entry in a dictionary, with the owning distribution as the value. Then, during _install_wheel, each file path from the wheel is checked against this dictionary to determine whether another distribution already owns it. If so, the path is recorded and later included in a warning.

However, the current approach only warns after the overwrite has already happened, which is not ideal. We could mitigate this by aborting the installation and requiring an explicit flag to continue, but unless we want to take a stricter approach, that may not be the best default behavior.

Another possible approach would be to prompt the user when conflicts are detected and require confirmation before proceeding. This is similar to aborting unless a flag is provided, but is more interactive and less strict.

Before going with any of the approaches above, though, I would like to get some input from the team on which one fits pip better. Please let me know if you have any ideas or suggestions on the implementation :).

Also, here is the output when installing two conflicting packages:

$ pip install isbnlib
Collecting isbnlib
  Using cached isbnlib-3.10.14-py2.py3-none-any.whl.metadata (16 kB)
Using cached isbnlib-3.10.14-py2.py3-none-any.whl (52 kB)
Installing collected packages: isbnlib
Successfully installed isbnlib-3.10.14
$ pip install isbnlib2
Collecting isbnlib2
  Using cached isbnlib2-3.11.21-py3-none-any.whl.metadata (16 kB)
Using cached isbnlib2-3.11.21-py3-none-any.whl (67 kB)
Installing collected packages: isbnlib2
  WARNING: Installing isbnlib2 overwrote 37 files (isbnlib/__init__.py, isbnlib/_core.py, isbnlib/_cover.py, and 34 more) which were already owned by isbnlib
Successfully installed isbnlib2-3.11.21

PR Checklist:

  • I agree to follow the PSF Code of Conduct.
  • I have read and have followed the CONTRIBUTING.md file.
  • I have added a news file fragment (or this PR does not need one).
  • I have read and followed the AI_POLICY.md file, and if any AI tools were used, I have disclosed it below.

@sepehr-rs

Copy link
Copy Markdown
Member Author

The failing tests are caused by the warnings from iter_all_distributions. I’ll try to find a minimal fix, but FWIW, once #14219 lands, I think this can be addressed more gracefully.

@notatallshaw

Copy link
Copy Markdown
Member

uv have been doing work on the same problem this year, and had to revert at least once due to user complaints. I will review the problems they had and if this will face the same issues.

@sepehr-rs

Copy link
Copy Markdown
Member Author

This also seems to be related to #8509, but running the repro script there further shows that this PR depends on #14219 landing and that the logging could be improved a bit further:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pip overwrites existing files unconditionally during installation

2 participants