Do not silently uninstall and install distinct versions of the same package
See original GitHub issueWhat’s the problem this feature will solve?
I am working on a tool that needs to automatically scan specific directories for a requirements file and install the specified dependencies in it. The problem is that if the requirements file is outdated, e.g. specifies an older version for an already installed package, the newer version will either be uninstalled and replaced by the older version or just overwritten by the older version if --ignore-installed is used.
Describe the solution you’d like I would like a solution where the whole process is aborted with an error message or at least the installation process for the affected packet is skipped, ideally with a single command. Otherwise this may break the python environment without a warning.
In my case I run the command to install dependencies via a requirements file via pythons subprocess.Popen class. Hence, for maximum automation, it would be ideal to be able to get the required behavior with a single command that either succeeds or fails.
Alternative Solutions A solution that would probably satisfy the biggest part of the use-cases would be to explicitly ask the user whether they want to uninstall and reinstall the dependency with specified version. It would also be nice to have the behaviour in both ways, i.e. neither silently replace newer nor older versions.
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
Yes, indeed both would be useful. The OP is actually kind of vague on what exactly is expected, so I have a feeling even
--upgrade-strategy=neveror any possible solution in pip may not solve their problem (a per-package prompt is a no-go, unroftunately).I agree that this interpretation (
==) is compatible with the title (“Do not silently uninstall and install distinct versions of the same package”). But the OP then points out the specific problem with older packages (which could be fixed using>=). Finally, they ask for an optional extension to also prevent newer packages, which would be==again. I can see both use cases (and solutions) as being useful.