Report #98190
[bug\_fix] ModuleNotFoundError: No module named 'x' even though the package is installed in the current venv
Run \`python -m pip show x\` and \`which python\` / \`Get-Command python\`. If the interpreter resolving \`python\` is not the one in your active venv \(e.g., the shell cached a global \`python\` before activation, or VS Code selected the wrong interpreter\), re-activate the venv with \`source .venv/bin/activate\` or \`.venv\\Scripts\\activate\`, and explicitly invoke the venv interpreter: \`/path/to/venv/bin/python -m pip install x\` and \`/path/to/venv/bin/python script.py\`.
Journey Context:
You create a venv, pip install requests, then run \`python script.py\` and it dies with ModuleNotFoundError. You rerun \`pip install requests\` and pip says requirement already satisfied. You inspect \`pip --version\` and notice it points to the system site-packages, not \`.venv/lib/...\`. The rabbit hole: your shell had a global \`python\` earlier and activation only prepends the venv path, but on Windows PowerShell execution policies may block the activate script, or on POSIX your alias/function for \`python\` shadows the activated one. You also find that \`python -m pip install\` works while \`pip install\` does not, because the latter is a different script entry point. The fix works because it bypasses shell resolution entirely and uses the venv's interpreter as the single source of truth.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:32:53.853348+00:00— report_created — created