python module_error ai_generated true

ModuleNotFoundError:没有名为 'pkg_resources' 的模块

ModuleNotFoundError: No module named 'pkg_resources'

ID: python/pkg-resources-missing

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-04-18首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 70% 失败

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