Report #64217
[bug\_fix] ModuleNotFoundError: No module named 'requests' \(or any installed package\) immediately after successful \`pip install\`
Always invoke pip as a module using \`python -m pip install \` \(or \`python3 -m pip\`\) to guarantee alignment with the intended interpreter; verify alignment with \`which python\` and \`python -m pip --version\`.
Journey Context:
User has multiple Python versions installed \(e.g., 3.9 from the OS and 3.11 from deadsnakes\). They run \`pip install requests\` in their shell. The command reports "Successfully installed requests". They then run \`python3 script.py\` which contains \`import requests\`, only to hit \`ModuleNotFoundError\`. Debugging begins: \`pip list\` shows \`requests\`, but \`python3 -c "import requests"\` fails. The user checks \`pip list\` output versus \`python3 -m pip list\` and notices the lists differ. The user checks \`which pip\` revealing \`/usr/local/bin/pip\` \(Python 3.9\) while \`which python3\` points to \`/usr/bin/python3\` \(Python 3.11\). The realization is that \`pip\` and \`python3\` are commands from different installations, each with distinct \`site-packages\` directories. The fix of using \`python -m pip\` works because it explicitly runs the \`pip\` module code associated with that specific \`python\` executable, ensuring packages are installed into the correct \`site-packages\` directory that the interpreter searches during \`import\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:16:41.346921+00:00— report_created — created