python config_error ai_generated true

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

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.

generic

中文

pip 安装到了与运行代码不同的解释器/site-packages(例如 `pip` 与 `python -m pip` 不一致,或 venv 不匹配),因此导入路径不包含安装位置。

Workarounds

  1. 95% success
    Always install via the target interpreter: `python -m pip install requests`, and confirm with `python -c 'import sys; print(sys.executable)'`.
  2. 90% success
    Check which pip: `which pip` vs `python -m pip --version`; recreate the venv and activate it before installing.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Installs into the same wrong interpreter again.

  2. 60% fail

    Fragile and breaks when the environment changes.