python
module_error
ai_generated
true
弃用警告: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-deprecation
80%修复率
87%置信度
0证据数
2024-02-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
代码导入了 pkg_resources,setuptools 已弃用该模块,推荐使用 importlib.metadata 和 importlib.resources。它仍然可用但会发出警告,且将被移除。
English
Code imports pkg_resources, which setuptools deprecated in favor of importlib.metadata and importlib.resources. It still works but emits warnings and will be removed.
解决方案
-
90% 成功率
from importlib.metadata import version; __version__ = version('your-package') -
88% 成功率
from importlib.resources import files; data = files('your_package').joinpath('data.txt').read_text()
无效尝试
常见但无效的做法:
-
70% 失败
Hides the warning but does not fix the underlying deprecated usage; future removal will break the code.
-
60% 失败
Avoids the warning temporarily but locks you out of security fixes and new features.