python
runtime_error
ai_generated
true
DeprecationWarning:pkg_resources 作为 API 已弃用。请参阅 https://setuptools.pypa.io/en/latest/pkg_resources.html
DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
ID: python/setuptools-pkg-resources-deprecated
80%修复率
85%置信度
0证据数
2024-04-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
代码导入 pkg_resources(例如用于入口点或资源访问);setuptools 67+ 将其标记为已弃用,推荐使用 importlib.metadata 和 importlib.resources。
English
Code imports pkg_resources (e.g., for entry points or resource access); setuptools 67+ flags it as deprecated in favor of importlib.metadata and importlib.resources.
解决方案
-
90% 成功率
from importlib.metadata import entry_points eps = entry_points(group='console_scripts') for ep in eps: print(ep.name, ep.value) -
88% 成功率
from importlib.resources import files data = (files('mypkg') / 'data.txt').read_text()
无效尝试
常见但无效的做法:
-
75% 失败
Hides warnings but pkg_resources will be removed, breaking the code later.
-
80% 失败
Blocks security fixes and conflicts with packages that require newer setuptools.