python module_error ai_generated true

UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30.

ID: python/setuptools-pkg-resources-deprecated-removed

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-03-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8+ active — — —

Root Cause

Code (directly or via a dependency) imports pkg_resources, which setuptools has deprecated and scheduled for removal. Common in older packages using pkg_resources.get_distribution or resource_filename.

generic

中文

代码(直接或通过依赖)导入了 pkg_resources,setuptools 已弃用该 API 并计划移除。常见于使用 pkg_resources.get_distribution 或 resource_filename 的旧包。

Workarounds

  1. 92% success
    from importlib.metadata import version, distribution
    print(version('requests'))
    
    from importlib.resources import files
    # replaces pkg_resources.resource_filename
    path = files('mypkg').joinpath('data.txt')
  2. 80% success
    python -W error::DeprecationWarning -c 'import mypkg'  # traceback shows importer
    pip install -U <offending-package>  # upgrade to a release using importlib

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Hides the symptom only; the import still executes and will hard-fail once pkg_resources is removed. Also masks the real migration need.

  2. 75% fail

    Pins you to an unsupported setuptools, breaks modern build backends, and merely defers the removal. Downstream packages may require newer setuptools.