python runtime_error ai_generated partial

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

ID: python/setuptools-pkg-resources-deprecation-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-09-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

Code or a dependency imports `pkg_resources`, which setuptools deprecated in favor of `importlib.metadata` and `importlib.resources`; under `-W error` it becomes a hard failure.

generic

中文

代码或依赖导入了 `pkg_resources`,setuptools 已弃用它,推荐改用 `importlib.metadata` 和 `importlib.resources`;在 `-W error` 下会变成硬错误。

Workarounds

  1. 90% success
    Migrate imports: replace `import pkg_resources; pkg_resources.get_distribution('x').version` with `from importlib.metadata import version; version('x')`.
  2. 70% success
    If the warning comes from a dependency, pin a fixed version or open an issue; locally silence only that line with `warnings.filterwarnings('ignore', category=UserWarning, module='pkg_resources')`.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Only postpones the removal; newer deps require modern setuptools.

  2. 50% fail

    Hides real issues and the API may be removed in a future release.