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

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

generic

解决方案

  1. 90% 成功率
    from importlib.metadata import entry_points
    eps = entry_points(group='console_scripts')
    for ep in eps:
        print(ep.name, ep.value)
  2. 88% 成功率
    from importlib.resources import files
    data = (files('mypkg') / 'data.txt').read_text()

无效尝试

常见但无效的做法:

  1. 75% 失败

    Hides warnings but pkg_resources will be removed, breaking the code later.

  2. 80% 失败

    Blocks security fixes and conflicts with packages that require newer setuptools.