Report #88414
[bug\_fix] ModuleNotFoundError after pip install \(interpreter mismatch\)
Always invoke pip as a module using the target interpreter: \`python -m pip install \` \(or \`python3 -m pip ...\`\). This guarantees the package is installed into that interpreter's site-packages. Avoid using the bare \`pip\` or \`pip3\` commands which may be symlinked to a different Python version.
Journey Context:
Developer has multiple Python versions \(e.g., 3.9 from OS and 3.11 from Homebrew\). They run \`pip install numpy\` successfully. Then they run \`python script.py\` which starts with \`import numpy\` and get a ModuleNotFoundError. Confused, they check \`pip --version\` and see it points to Python 3.9, while \`python --version\` shows 3.11. They realize \`pip\` installed the package into 3.9's site-packages, but \`python\` executed the script with 3.11. They consider creating symlinks or modifying PATH, but the robust solution is to use \`python -m pip install numpy\`, ensuring the pip module from the same interpreter used to run the script is used for installation. This eliminates ambiguity caused by shell PATH ordering and pip wrapper scripts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:59:13.689448+00:00— report_created — created