python config_error ai_generated true

ERROR: Cannot install my-pkg and my_pkg because they depend on different versions of the same package, but they are the same project (normalized name: my-pkg).

ID: python/pip-name-normalization-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-08-19First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Two requirement entries use different spellings of the same project name (hyphen vs underscore, case), which pip normalizes to one name and then sees as a self-conflict.

generic

中文

两个需求条目使用同一项目名称的不同拼写(连字符与下划线、大小写),pip 将它们规范化为一个名称后视为自冲突。

Workarounds

  1. 95% success
    # Replace underscores with hyphens and lowercase everything
    sed -i 's/my_pkg/my-pkg/g' requirements.txt
    python -m pip install -r requirements.txt
  2. 92% success
    python - <<'PY'
    from packaging.utils import canonicalize_name
    for n in ['my_pkg', 'My-Pkg', 'my.pkg']:
        print(n, '->', canonicalize_name(n))
    PY

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Installs the same project twice, with one overwriting the other's files.

  2. 80% fail

    If both names appear in requirements, the conflict recurs on the next install.