python module_error ai_generated true

ModuleNotFoundError: No module named 'requests'

ID: python/pip-module-not-found-after-install

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

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).

generic

中文

包被安装到了与运行脚本不同的 Python 解释器/site-packages 中(例如 pip 与 python3 不同,或虚拟环境未激活)。

Workarounds

  1. 95% success
    python -m pip install requests  # use the same python that runs your script
  2. 90% success
    python -c "import sys; print(sys.executable, sys.path)"
    python -m pip show requests

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Installs into the system Python, not the active interpreter, worsening the mismatch.

  2. 60% fail

    Does not fix the interpreter mismatch and breaks when environments change.