Report #23935
[bug\_fix] ModuleNotFoundError immediately after 'pip install package' in a virtual environment
Use 'python -m pip install ' instead of invoking 'pip' directly, or ensure the virtual environment is activated so the shell's PATH resolves 'pip' from the venv's bin/ directory.
Journey Context:
Developer creates a fresh venv, activates it in Terminal Tab 1, and installs packages. In Terminal Tab 2, they forget to activate the venv and run 'pip install requests' which executes /usr/bin/pip \(system\) installing to global site-packages. They then run 'python script.py' using the venv's python binary. The script fails with ModuleNotFoundError. Checking 'which pip' vs 'which python' reveals the mismatch. The debugging rabbit hole involves checking sys.path, site-packages locations, and realizing that 'pip' and 'python' on PATH refer to different installations. Using 'python -m pip' ensures the pip module associated with that specific python binary is invoked, eliminating PATH confusion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:35:16.181613+00:00— report_created — created