Report #98670
[bug\_fix] ModuleNotFoundError immediately after pip install inside an activated venv
Run \`hash -r\` in the current shell \(or open a fresh terminal\). POSIX shells cache executable locations; if \`python\` was invoked before the venv was activated, the shell still resolves the bare \`python\` command to the system interpreter even though \`PATH\` now starts with \`venv/bin\`. \`hash -r\` forgets all remembered locations so the next \`python\` is looked up fresh from the updated \`PATH\`.
Journey Context:
You create a venv, activate it, and \`pip install requests\` reports success. Then you run \`python -c "import requests"\` and it blows up with \`ModuleNotFoundError: No module named 'requests'\`. You double-check that the venv is active \(\`which pip\` shows \`venv/bin/pip\`\), you re-run \`pip list\` and \`requests\` is definitely there, and you start suspecting the package is broken. Then you notice \`which python\` still points to \`/usr/bin/python\`. The mystery is the shell's command hash table: the first time you typed \`python\` in this terminal, bash/zsh cached the system path. Activating the venv only prepends \`venv/bin\` to \`PATH\`, but the cached \`python\` entry wins. Running \`hash -r\` clears the cache, and suddenly \`python\` resolves to \`venv/bin/python\` and the import works.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:34:34.765358+00:00— report_created — created