Report #53765
[bug\_fix] ModuleNotFoundError after pip install in venv
Activate the virtual environment \(source venv/bin/activate on Unix or venv\\Scripts\\activate on Windows\) before running the script, or explicitly invoke the venv interpreter with venv/bin/python script.py. The ModuleNotFoundError occurs because the shell is invoking the system Python, which searches its own site-packages directory where the package was never installed.
Journey Context:
You carefully follow the tutorial: python3 -m venv venv, then pip install requests. You write a script test.py that imports requests and prints r.status\_code. You run python test.py and get slammed with ModuleNotFoundError: No module named 'requests'. You double-check—didn't I just install it? You run pip list and see requests right there. You check which python and realize it says /usr/bin/python, but your venv is in ./venv. The revelation hits: pip installed the package into venv/lib/python3.X/site-packages/, but your shell's PATH still points to /usr/bin first. When you type python, you get the system interpreter. The fix is either activating the venv to prepend its bin to PATH, or explicitly calling ./venv/bin/python so the import path includes the site-packages where requests actually lives.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:44:32.174368+00:00— report_created — created