python module_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-deprecation

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-02-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

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

中文

代码导入了 pkg_resources,setuptools 已弃用该模块,推荐使用 importlib.metadata 和 importlib.resources。它仍然可用但会发出警告,且将被移除。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

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

  2. 60% fail

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