python
module_error
ai_generated
true
ModuleNotFoundError: 没有名为 'requests' 的模块
ModuleNotFoundError: No module named 'requests'
ID: python/pip-module-not-found-after-install
80%修复率
88%置信度
0证据数
2024-03-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
包被安装到了与运行脚本不同的 Python 解释器/site-packages 中(例如 pip 与 python3 不同,或虚拟环境未激活)。
English
Package was installed into a different Python interpreter/site-packages than the one running the script (e.g., pip vs python3, or a virtualenv not activated).
解决方案
-
95% 成功率
python -m pip install requests # use the same python that runs your script
-
90% 成功率
python -c "import sys; print(sys.executable, sys.path)" python -m pip show requests
无效尝试
常见但无效的做法:
-
70% 失败
Installs into the system Python, not the active interpreter, worsening the mismatch.
-
60% 失败
Does not fix the interpreter mismatch and breaks when environments change.