Report #66721
[bug\_fix] ModuleNotFoundError after pip install due to venv interpreter mismatch
Use \`python -m pip install \` instead of the bare \`pip\` command to guarantee alignment with the target interpreter. If the shell has cached the system \`pip\` command, clear the hash with \`hash -r\` \(bash\) or start a fresh shell after activating the venv.
Journey Context:
A developer creates a venv with \`python3 -m venv .venv\` on Ubuntu, then immediately runs \`pip install requests\` without activating the shell \(or assuming the venv is active\). Because the shell's \`pip\` command is hashed to \`/usr/bin/pip\`, the package installs into the system or user site-packages. When the developer later activates the venv and runs \`python script.py\`, they get \`ModuleNotFoundError\`. They verify with \`pip list\` \(shows requests\) but \`python -m pip list\` \(does not show requests\). Realizing the mismatch, they deactivate, run \`hash -r\` to clear the shell's command cache, reactivate, and adopt the habit of using \`python -m pip\` exclusively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:28:29.711624+00:00— report_created — created