python config_error ai_generated true

错误:无法安装 my-pkg 和 my_pkg,因为它们依赖同一包的不同版本,但它们是同一个项目(规范化名称:my-pkg)。

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

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2024-08-19首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

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

解决方案

  1. 95% 成功率
    # 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% 成功率
    python - <<'PY'
    from packaging.utils import canonicalize_name
    for n in ['my_pkg', 'My-Pkg', 'my.pkg']:
        print(n, '->', canonicalize_name(n))
    PY

无效尝试

常见但无效的做法:

  1. 85% 失败

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

  2. 80% 失败

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