# 错误：无法安装 my-pkg 和 my_pkg，因为它们依赖同一包的不同版本，但它们是同一个项目（规范化名称：my-pkg）。

- **ID:** `python/pip-name-normalization-conflict`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **** — Installs the same project twice, with one overwriting the other's files. (85% 失败率)
- **** — If both names appear in requirements, the conflict recurs on the next install. (80% 失败率)
