ERROR pip config_error ai_generated true

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-03-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 22.3 active
pip 23.0 active
pip 23.2.1 active

Root Cause

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.

generic

中文

用户在 requirements.txt 中固定了一个与当前已安装版本不同的版本,pip 的解析器无法协调此冲突,因为已安装的版本违反了约束。

Official Documentation

https://pip.pypa.io/en/stable/topics/repeatable-installs/#using-requirements-files

Workarounds

  1. 90% success Update requirements.txt to match the installed version: run `pip freeze | grep <package>` and replace the version in requirements.txt with the output. Example: `pip freeze | grep requests` then set `requests==2.31.0` in requirements.txt.
    Update requirements.txt to match the installed version: run `pip freeze | grep <package>` and replace the version in requirements.txt with the output. Example: `pip freeze | grep requests` then set `requests==2.31.0` in requirements.txt.
  2. 75% success Use `--ignore-installed` with pip install to bypass the check: `pip install -r requirements.txt --ignore-installed <package>`
    Use `--ignore-installed` with pip install to bypass the check: `pip install -r requirements.txt --ignore-installed <package>`

中文步骤

  1. 更新 requirements.txt 以匹配已安装的版本:运行 `pip freeze | grep <package>` 并将 requirements.txt 中的版本替换为输出。示例:`pip freeze | grep requests` 然后在 requirements.txt 中设置 `requests==2.31.0`。
  2. 使用 `--ignore-installed` 与 pip install 绕过检查:`pip install -r requirements.txt --ignore-installed <package>`

Dead Ends

Common approaches that don't work:

  1. 70% fail

    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.

  2. 60% fail

    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.