Report #47810
[bug\_fix] ModuleNotFoundError: No module named 'requests' \(despite pip install showing Requirement already satisfied\)
Use \`python -m pip install \` instead of \`pip install \`, or explicitly invoke the pip associated with the target interpreter \(e.g., \`venv/bin/pip\`\). Root cause: The \`pip\` command in PATH is often linked to a different Python interpreter \(system Python, Python 2.7, or a different venv\) than the \`python\` command used to run the code, causing packages to install into the wrong site-packages directory.
Journey Context:
Developer creates a virtual environment with \`python3 -m venv myenv\` and activates it with \`source myenv/bin/activate\`. They run \`pip install requests\` which reports successful installation. They then execute \`python script.py\` which imports requests, but it crashes with \`ModuleNotFoundError: No module named 'requests'\`. They check \`which pip\` and see \`/usr/bin/pip\` \(system pip\), while \`which python\` shows \`~/myenv/bin/python\`. The activation script modified PATH, but \`pip\` was earlier in PATH from a previous shell configuration, or the venv's pip wasn't executable. Using \`python -m pip install requests\` forces the use of the pip module associated with the specific python interpreter, ensuring packages install into \`myenv/lib/python3.x/site-packages/\`, matching the runtime environment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:43:52.784764+00:00— report_created — created