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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 90% 成功率
    from importlib.metadata import version; __version__ = version('your-package')
  2. 88% 成功率
    from importlib.resources import files; data = files('your_package').joinpath('data.txt').read_text()

无效尝试

常见但无效的做法:

  1. 70% 失败

    Hides the warning but does not fix the underlying deprecated usage; future removal will break the code.

  2. 60% 失败

    Avoids the warning temporarily but locks you out of security fixes and new features.