Report #70174
[bug\_fix] ModuleNotFoundError after \`pip install\` because pip installed into the global interpreter while the script runs inside a venv
Install with the interpreter you run with: \`/path/to/venv/bin/python -m pip install \` \(or activate the venv first, then \`python -m pip install \`\). Verify with \`python -c "import sys; print\(sys.executable\)"\` and \`python -m pip --version\`.
Journey Context:
You created a venv, then in a fresh terminal ran \`pip install requests\`, but your script still fails with \`ModuleNotFoundError: No module named 'requests'\`. You check \`which python\` and it is \`/usr/bin/python\`; \`which pip\` is \`/usr/local/bin/pip\` because the shell PATH puts the global tools first. Running \`python -m pip list\` shows requests is missing, while \`/usr/bin/pip list\` shows it installed. The rabbit hole is that the venv only prepends its \`bin/\` directory to PATH after \`source venv/bin/activate\`; without activation, \`python\` and \`pip\` can point at unrelated global binaries. The fix works because a venv is a separate installation context \(PEP 405\) with its own \`sys.prefix\` and \`site-packages\`; packages installed into global \`site-packages\` do not appear inside it. Using \`python -m pip\` ties the installer to the runtime unambiguously.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:22:08.824167+00:00— report_created — created