Report #9475
[bug\_fix] ModuleNotFoundError immediately after 'pip install' inside a virtual environment \(caused by invoking the global pip\)
Always use 'python -m pip install ' instead of the bare 'pip' command. This ensures you are using the pip associated with the Python interpreter currently active in your shell, preventing installation into the wrong site-packages.
Journey Context:
You create a fresh virtual environment with 'python3 -m venv .venv' and activate it with 'source .venv/bin/activate'. You run 'pip install requests' and see a success message. You then run your application with 'python app.py' and get ModuleNotFoundError: No module named 'requests'. You check 'which python' and it correctly points to '.venv/bin/python', but when you check 'which pip', it points to '/usr/bin/pip' \(the global pip\). You realize that your shell's PATH or an alias caused 'pip' to bypass the venv's shim. The packages were installed into the global site-packages, not the venv. You uninstall from global, then run 'python -m pip install requests', which explicitly uses the venv's Python and pip module. The import then succeeds in your application.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:16:27.635211+00:00— report_created — created