Report #75667
[bug\_fix] ModuleNotFoundError after pip install \(interpreter mismatch\)
Use \`python -m pip install\` instead of \`pip install\` directly, or ensure the virtual environment is fully activated \(deactivate/activate cycle\). Root cause: The \`pip\` command in PATH resolves to a different Python interpreter \(e.g., system \`/usr/bin/pip\`\) than the \`python\` command \(e.g., \`venv/bin/python\`\), causing packages to install into the global site-packages while the script runs from the venv's empty site-packages.
Journey Context:
You create a venv with \`python3 -m venv venv\` and activate it with \`source venv/bin/activate\`. You run \`pip install requests\`, which succeeds. You run \`python main.py\` which imports \`requests\`, but it crashes with \`ModuleNotFoundError\`. You verify with \`pip list\` showing \`requests\` is installed, but \`python -c "import requests"\` fails. You check \`which pip\` showing \`/usr/bin/pip\` and \`which python\` showing \`/home/user/project/venv/bin/python\`. The shell had cached the system \`pip\` command before activation, or the PATH order is wrong. The fix is to use \`python -m pip install requests\`, which ensures you are using the \`pip\` module associated with the specific Python interpreter you are invoking, bypassing the PATH confusion entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:36:32.632899+00:00— report_created — created