Report #92420
[bug\_fix] ModuleNotFoundError after pip install \(interpreter mismatch\)
Use 'python -m pip install ' instead of bare 'pip install', ensuring the pip module runs from the same interpreter that will execute the script. Alternatively, explicitly invoke the venv python: '.venv/bin/python -m pip install' and '.venv/bin/python script.py'.
Journey Context:
Developer creates a fresh venv with 'python3 -m venv .venv' and activates it with 'source .venv/bin/activate'. They run 'pip install requests' which reports success. However, running 'python script.py' immediately fails with ModuleNotFoundError: No module named 'requests'. Debugging reveals 'which python' returns '/usr/bin/python' \(system Python\) while 'which pip' returns '.venv/bin/pip'. The shell activation modified PATH but the terminal session was restarted or VS Code launched a sub-shell without inheriting the activated environment, causing python to resolve to the system interpreter while pip resolved to the venv. Using 'python -m pip' forces the pip module to be imported from the same interpreter that will later import the installed package, ensuring consistency regardless of PATH confusion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:43:09.358342+00:00— report_created — created