Report #39047
[bug\_fix] ModuleNotFoundError: No module named 'requests' \(or any installed package\) despite 'pip list' showing it installed
Activate the virtual environment \(source .venv/bin/activate or .venv\\Scripts\\activate\) or explicitly invoke the Python interpreter from the venv \(.venv/bin/python script.py\). The root cause is that the 'python' or 'python3' command used to run the script resolves to the system interpreter \(e.g., /usr/bin/python\) which does not search the venv's site-packages directory. Activating the venv prepends its bin/ directory to PATH, ensuring 'python' maps to the venv interpreter that has the correct sys.path.
Journey Context:
The developer creates a venv with 'python3 -m venv .venv', installs dependencies with '.venv/bin/pip install requests', then runs 'python script.py'. The script fails with ModuleNotFoundError. The developer checks '.venv/bin/pip list' and sees 'requests' is installed, creating confusion. They check 'which python' and see '/usr/bin/python', realizing the shell is using the system Python. They try 'python3 script.py' and get the same error. Finally, they run '.venv/bin/python script.py' and the script works, confirming the PATH mismatch. They realize 'source .venv/bin/activate' is necessary to avoid typing the full path every time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:00:59.745579+00:00— report_created — created