python
module_error
ai_generated
true
ModuleNotFoundError:没有名为 'pkg_resources' 的模块
ModuleNotFoundError: No module named 'pkg_resources'
ID: python/pkg-resources-missing
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.
解决方案
-
95% 成功率
Install setuptools into the active environment: python -m pip install setuptools
-
85% 成功率
Migrate to importlib.metadata / importlib.resources: from importlib.metadata import version print(version('requests'))
无效尝试
常见但无效的做法:
-
95% 失败
There is no standalone pkg_resources package on PyPI; it ships inside setuptools.
-
70% 失败
Silences the error but any code depending on resource access still fails later.