python config_error ai_generated true

警告:忽略无效的分发 -ip(位于 site-packages)。错误:无效的需求:'foo=>1.0'(来自 requirements.txt 第 1 行)。提示:= 不是有效运算符,是否想用 ==?

WARNING: Ignoring invalid distribution -ip (c:\python311\lib\site-packages) ERROR: Invalid requirement: 'foo=>1.0' (from line 1 of requirements.txt) Hint: = is not a valid operator. Did you mean == ?

ID: python/pip-requires-python-metadata-missing

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

版本兼容性

版本状态引入弃用备注
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

根因分析

requirements 文件使用了无效的版本运算符(=> 而非 >=)或 packaging 拒绝的格式错误说明符。此外,部分卸载的发行版在 site-packages 中残留了 '~ip' 或 '-ip' 存根目录。

English

The requirements file uses an invalid version operator (=> instead of >=) or a malformed specifier that packaging rejects. Additionally a partially uninstalled distribution left a '~ip' or '-ip' stub directory in site-packages.

generic

解决方案

  1. 93% 成功率
    sed -i 's/=>/>=/g' requirements.txt
    # remove leftover '~' dirs
    find $(python -c 'import site; print(site.getsitepackages()[0])') -maxdepth 1 -name '~*' -exec rm -rf {} +
    pip install -r requirements.txt
  2. 90% 成功率
    python -c "from packaging.requirements import Requirement; [Requirement(l) for l in open('requirements.txt') if l.strip() and not l.startswith('#')]"

无效尝试

常见但无效的做法:

  1. 90% 失败

    The syntax error is in the requirements file, not pip; upgrading changes nothing and the invalid operator still fails.

  2. 70% 失败

    Overly destructive; breaks the base interpreter and does not fix the malformed requirements line.