# 错误：无效的依赖项：'Requires-Python: >=3.8'

- **ID:** `python/pip-requires-python-invalid-metadata`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

requirements.txt 包含从 PKG-INFO 粘贴的包元数据行（如 Requires-Python 或 Name:），pip 的依赖解析器会拒绝它们。

## 版本兼容性

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

## 解决方案

1. **** (98% 成功率)
   ```
   # requirements.txt should look like:
requests>=2.31
numpy==1.26.4
# Remove any 'Name:', 'Version:', 'Requires-Python:' lines.
   ```
2. **** (95% 成功率)
   ```
   pip freeze > requirements.txt
# verify each line parses
python - <<'PY'
from packaging.requirements import Requirement
for i, l in enumerate(open('requirements.txt'),1):
    l=l.strip()
    if l and not l.startswith('#'):
        Requirement(l)
print('ok')
PY
   ```

## 无效尝试

- **** — If other metadata lines remain, parsing still fails; also hides the actual intent of the file. (60% 失败率)
- **** — --no-deps skips dependency resolution, not requirement parsing; the invalid line still errors. (90% 失败率)
