python
config_error
ai_generated
true
需求已满足:requests 位于 ./venv/lib/python3.11/site-packages (2.31.0) >>> import requests ModuleNotFoundError: 没有名为 'requests' 的模块
Requirement already satisfied: requests in ./venv/lib/python3.11/site-packages (2.31.0) >>> import requests ModuleNotFoundError: No module named 'requests'
ID: python/pip-requirement-already-satisfied-but-import-fails
80%修复率
88%置信度
0证据数
2024-03-27首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
pip 安装到了与运行代码不同的解释器/site-packages(例如 `pip` 与 `python -m pip` 不一致,或 venv 不匹配),因此导入路径不包含安装位置。
English
pip installed into a different interpreter/site-packages than the one running the code (e.g. `pip` vs `python -m pip`, or a mismatched venv), so the import path does not include the install location.
解决方案
-
95% 成功率
Always install via the target interpreter: `python -m pip install requests`, and confirm with `python -c 'import sys; print(sys.executable)'`.
-
90% 成功率
Check which pip: `which pip` vs `python -m pip --version`; recreate the venv and activate it before installing.
无效尝试
常见但无效的做法:
-
90% 失败
Installs into the same wrong interpreter again.
-
60% 失败
Fragile and breaks when the environment changes.