python module_error ai_generated true

ModuleNotFoundError: No module named 'pkg_resources'

ID: python/pkg-resources-missing

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

setuptools is not installed in the active environment, or the environment was created without setuptools (e.g., some venv setups or distro Python without pip). Code importing pkg_resources fails.

generic

中文

当前环境中未安装 setuptools,或环境创建时未包含 setuptools(例如某些 venv 配置或未安装 pip 的发行版 Python)。导入 pkg_resources 的代码因此失败。

Workarounds

  1. 95% success
    Install setuptools into the active environment:
    python -m pip install setuptools
  2. 85% success
    Migrate to importlib.metadata / importlib.resources:
    from importlib.metadata import version
    print(version('requests'))

Dead Ends

Common approaches that don't work:

  1. 95% fail

    There is no standalone pkg_resources package on PyPI; it ships inside setuptools.

  2. 70% fail

    Silences the error but any code depending on resource access still fails later.