Report #100050
[bug\_fix] ModuleNotFoundError after \`pip install \`: package installs into a different Python interpreter than the one running the script
Run the interpreter's own pip via \`python -m pip install \` \(or \`/bin/python -m pip install \`\) instead of the bare \`pip\` command. If the environment already has stale packages in the wrong interpreter, create a fresh venv with \`python3 -m venv .venv\` and always invoke pip as a module.
Journey Context:
A developer installs a package with \`pip install requests\`, then runs \`python myscript.py\` and immediately gets \`ModuleNotFoundError: No module named 'requests'\`. They run \`pip list\` and see \`requests\` is installed, so they conclude pip is broken. Then they notice \`which python\` points to \`/usr/bin/python3\` while \`which pip\` points to \`~/.local/bin/pip\`, which was bootstrapped from a different Python or a Homebrew/conda installation. The package was installed into \`site-packages\` for pip's interpreter, not the script's interpreter. The confusion deepens when \`sudo pip install\` puts the package into the system Python while the user runs a pyenv or conda Python. The fix works because \`python -m pip\` guarantees that the pip being executed is the one belonging to the exact interpreter that will import the package, eliminating PATH shadowing and interpreter skew.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:34:41.003005+00:00— report_created — created