python
module_error
ai_generated
true
SetuptoolsDeprecationWarning: pkg_resources 作为 API 已弃用。
SetuptoolsDeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
ID: python/setuptools-pkg-resources-deprecated
80%修复率
88%置信度
0证据数
2024-01-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
代码(通常是第三方库)导入了 pkg_resources,setuptools 计划移除它;该警告在导入时出现。
English
Code (often a third-party library) imports pkg_resources, which setuptools plans to remove; the warning surfaces at import time.
解决方案
-
90% 成功率
Replace pkg_resources usage with importlib.metadata: # old: pkg_resources.get_distribution('foo').version from importlib.metadata import version version('foo') -
80% 成功率
If the import is inside a third-party lib, upgrade it: pip install --upgrade <lib> Check with: pip list --outdated
-
60% 成功率
Suppress narrowly in pyproject.toml [tool.pytest.ini_options] filterwarnings if you cannot upgrade yet.
无效尝试
常见但无效的做法:
-
80% 失败
Newer setuptools still ships pkg_resources but emits the warning; upgrading does not silence it.
-
60% 失败
Hides the warning but the underlying API will be removed; the library will break eventually.