Report #27409
[bug\_fix] ModuleNotFoundError: No module named 'requests'
Use 'python -m pip install ' instead of 'pip install ', or explicitly activate the virtual environment before running pip. This ensures the package is installed into the site-packages of the interpreter that will execute the code, eliminating interpreter mismatches.
Journey Context:
A developer runs 'pip install requests' which reports success, but executing 'python script.py' immediately raises 'ModuleNotFoundError: No module named requests'. Checking 'pip list' confirms requests is installed, creating confusion. The developer checks 'which pip' and 'which python' and discovers '/usr/bin/pip' is associated with Python 3.8 while '/usr/local/bin/python' is Python 3.11. The package was installed into Python 3.8's site-packages, but the script runs with 3.11 which has an empty site-packages. The realization dawns that 'pip' and 'python' are decoupled binaries. Switching to 'python -m pip install requests' forces pip to install into the correct interpreter's environment, and the script subsequently finds the module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:24:17.294018+00:00— report_created — created