Report #59694
[bug\_fix] ModuleNotFoundError after pip install succeeds \(pip installs to different Python than expected\)
Always invoke pip as a module using \`python -m pip install \` instead of running the \`pip\` command directly. The \`pip\` executable is a script with a shebang line pointing to the Python interpreter that was used to install pip itself. If your shell's \`python\` command points to a different interpreter \(e.g., \`python3\` vs \`python\`, Homebrew vs system, pyenv local vs global\), packages install into that pip-associated interpreter's site-packages, while \`python\` looks elsewhere. Using \`python -m pip\` guarantees the pip module runs under the exact interpreter you intend to use.
Journey Context:
Developer on macOS runs \`pip install numpy\`. Terminal reports "Successfully installed numpy-1.24.0". They run \`python script.py\` which imports numpy and immediately get \`ModuleNotFoundError: No module named 'numpy'\`. They run \`which pip\` which shows \`/usr/local/bin/pip\`. They run \`which python\` which shows \`/usr/bin/python\`. They check \`pip --version\` and see "pip 23.0 from .../python3.11/...". They realize that \`pip\` is from Homebrew Python 3.11, while \`python\` is the system Python 3.9. The package installed to the 3.11 site-packages. They run \`python3 -m pip install numpy\` \(using Homebrew's python3\) and the import works. They now adopt the habit of \`python -m pip\` to ensure alignment.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:41:14.592278+00:00— report_created — created