python
runtime_error
ai_generated
partial
DeprecationWarning: pkg_resources 作为 API 已被弃用。参见 https://setuptools.pypa.io/en/latest/pkg_resources.html UserWarning: pkg_resources 作为 API 已被弃用。
DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html UserWarning: pkg_resources is deprecated as an API.
ID: python/setuptools-pkg-resources-deprecation-error
80%修复率
83%置信度
0证据数
2024-09-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
代码或依赖导入了 `pkg_resources`,setuptools 已弃用它,推荐改用 `importlib.metadata` 和 `importlib.resources`;在 `-W error` 下会变成硬错误。
English
Code or a dependency imports `pkg_resources`, which setuptools deprecated in favor of `importlib.metadata` and `importlib.resources`; under `-W error` it becomes a hard failure.
解决方案
-
90% 成功率
Migrate imports: replace `import pkg_resources; pkg_resources.get_distribution('x').version` with `from importlib.metadata import version; version('x')`. -
70% 成功率
If the warning comes from a dependency, pin a fixed version or open an issue; locally silence only that line with `warnings.filterwarnings('ignore', category=UserWarning, module='pkg_resources')`.
无效尝试
常见但无效的做法:
-
70% 失败
Only postpones the removal; newer deps require modern setuptools.
-
50% 失败
Hides real issues and the API may be removed in a future release.