python runtime_error ai_generated true

DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

ID: python/setuptools-pkg-resources-deprecated

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-04-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

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

中文

代码导入 pkg_resources(例如用于入口点或资源访问);setuptools 67+ 将其标记为已弃用,推荐使用 importlib.metadata 和 importlib.resources。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 75% fail

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

  2. 80% fail

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