python config_error ai_generated true

ERROR: Cannot install Foo-Bar==1.0 and foo_bar==1.1 because these package versions have conflicting dependencies.

ID: python/pip-normalize-name-case-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2025-03-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

Two requirement lines specify the same distribution using different name spellings; PEP 503 normalization treats them as equal, so pinning two versions conflicts.

generic

中文

两行依赖使用不同的名称拼写指定了同一个分发包;PEP 503 规范化将它们视为相同,因此固定两个版本会冲突。

Workarounds

  1. 95% success
    python - <<'PY'
    from packaging.utils import canonicalize_name
    seen = {}
    for line in open('requirements.txt'):
        line = line.strip()
        if not line or line.startswith('#'):
            continue
        name = line.split('==')[0]
        canon = canonicalize_name(name)
        if canon in seen:
            print('duplicate:', line, 'vs', seen[canon])
        else:
            seen[canon] = line
    PY
  2. 98% success
    # requirements.txt
    foo-bar==1.1
    # remove the duplicate foo_bar==1.0 line
    pip install -r requirements.txt

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Skips dependency resolution but the two conflicting top-level pins still cannot coexist.

  2. 85% fail

    Force-reinstall does not reconcile versions; the resolver still reports the conflict.