Report #71335
[bug\_fix] ModuleNotFoundError after pip install \(packages installed to different interpreter\)
Always use \`python -m pip install\` instead of the bare \`pip install\` command to guarantee alignment with the intended interpreter.
Journey Context:
Developer activates a venv with \`source venv/bin/activate\`. Runs \`pip install requests\`. Then runs \`python script.py\` which imports requests, getting ModuleNotFoundError. \`pip list\` shows requests is installed, but \`python -m pip list\` shows it's missing. Developer checks \`which pip\` \(shows /usr/bin/pip\) vs \`which python\` \(shows /home/user/venv/bin/python\). The shell had cached the pip command hash or the PATH order placed system pip before venv pip. The venv’s pip wrapper was never invoked, so requests installed into the system Python’s site-packages. Using \`python -m pip\` executes the pip module using the same Python binary that will run the script, bypassing any PATH issues with wrapper scripts and ensuring packages install into sys.path for that specific interpreter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:18:39.884833+00:00— report_created — created