Report #6892
[bug\_fix] ModuleNotFoundError: No module named 'requests' \(or any package\) immediately after 'pip install' appeared to succeed
Use 'python -m pip install ' instead of bare 'pip install'. This guarantees the pip module is loaded from the same Python interpreter that will run the code, ensuring packages land in the correct site-packages directory.
Journey Context:
Developer creates a venv with 'python3.11 -m venv .venv' and activates it with 'source .venv/bin/activate'. They run 'pip install requests', which reports success. However, running 'python myscript.py' that imports requests crashes with ModuleNotFoundError. The developer checks 'which pip' and sees '/usr/bin/pip' \(system Python 3.9\), while 'which python' shows '/path/to/.venv/bin/python' \(3.11\). The activation script failed to prepend .venv/bin to PATH because the shell was launched from an IDE that cached the old environment. Consequently, pip installed requests into the system site-packages, but the venv Python only searches its own site-packages. Using 'python -m pip install' forces the pip module from the venv's stdlib, bypassing the PATH issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:17:05.895585+00:00— report_created — created