Report #54162
[bug\_fix] ModuleNotFoundError: No module named 'requests' \(after pip install requests in activated venv\)
The root cause is a split personality between the \`pip\` command and the \`python\` command; \`pip\` installs packages into the venv's \`site-packages\` but \`python\` executes the system interpreter \(or vice versa\) because PATH ordering, shell aliases, or incomplete venv activation causes a mismatch. The fix is to always use \`python -m pip install \` instead of \`pip install \`, ensuring the pip module is executed by the same python interpreter that will run the code, or explicitly verify \`which python\` and \`which pip\` resolve to the same \`bin/\` directory.
Journey Context:
Developer creates a venv with \`python3 -m venv .venv\` and activates it with \`source .venv/bin/activate\`. They see the prompt change indicating activation. They run \`pip install flask\` which reports successful installation. They then run \`python app.py\` and immediately get \`ModuleNotFoundError: No module named 'flask'\`. Confused, they run \`pip list\` and see Flask listed, but \`python -c "import flask"\` fails. They check \`pip --version\` and see it is associated with the .venv path. Then they check \`which python\` and see \`/usr/bin/python\` instead of \`.venv/bin/python\`. They realize their shell has a function or alias \`python\` pointing to system Python while \`pip\` was correctly shimmed by the activation script. Using \`python -m pip install flask\` would have failed immediately with the same ModuleNotFoundError, revealing the mismatch instantly. The fix ensures alignment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:24:33.740761+00:00— report_created — created