# packaging.version.InvalidVersion：无效版本：'1.0.0-rc.1+build.5.6.7.8.9.10'

- **ID:** `python/pip-version-parse-invalid-version`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

包版本字符串不符合 PEP 440。这通常发生在自定义构建或内置包上，其版本从包含无效字符的 git describe 或 CI 变量设置而来。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (80% 成功率)
   ```
   from packaging.version import Version, InvalidVersion

def normalize(v):
    try:
        return str(Version(v))
    except InvalidVersion:
        return v.replace('-rc.', 'rc').replace('+', '.post')

print(normalize('1.0.0-rc.1'))  # 1.0.0rc1
   ```
2. **** (85% 成功率)
   ```
   # in setup.py
from setuptools import setup
setup(name='mypkg', version='1.0.0rc1')  # not 1.0.0-rc.1
   ```

## 无效尝试

- **** — Pre-release flag doesn't relax PEP 440 validation; the version string is still invalid. (90% 失败率)
- **** — Ignoring installed packages doesn't change version parsing. (85% 失败率)
