错误:pip 的依赖解析器检测到冲突的要求。requirements.txt 文件包含 '<package>==1.0',但 pip freeze 显示已安装 '<package>==2.0'。
ERROR: pip's dependency resolver detected conflicting requirements. The requirements.txt file contains '<package>==1.0' but pip freeze shows '<package>==2.0' installed.
ID: pip/conflict-with-requirements-txt-and-pip-freeze
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 22.3 | active | — | — | — |
| pip 23.0 | active | — | — | — |
| pip 23.2.1 | active | — | — | — |
根因分析
用户在 requirements.txt 中固定了一个与当前已安装版本不同的版本,pip 的解析器无法协调此冲突,因为已安装的版本违反了约束。
English
The user has a pinned version in requirements.txt that differs from the currently installed version, and pip's resolver cannot reconcile the conflict because the installed version violates the constraint.
官方文档
https://pip.pypa.io/en/stable/topics/repeatable-installs/#using-requirements-files解决方案
-
更新 requirements.txt 以匹配已安装的版本:运行 `pip freeze | grep <package>` 并将 requirements.txt 中的版本替换为输出。示例:`pip freeze | grep requests` 然后在 requirements.txt 中设置 `requests==2.31.0`。
-
使用 `--ignore-installed` 与 pip install 绕过检查:`pip install -r requirements.txt --ignore-installed <package>`
无效尝试
常见但无效的做法:
-
70% 失败
The upgrade may break other dependencies that rely on the newer version; pip's resolver will still complain if the upgrade is not possible due to other constraints.
-
60% 失败
This removes the constraint entirely, but pip may still detect the version mismatch if the package is a dependency of another package in the file.