Report #51760
[bug\_fix] ModuleNotFoundError: No module named 'XXX' despite pip install succeeding
Use \`python -m pip install\` instead of bare \`pip install\` to guarantee alignment, and verify the interpreter path with \`python -c "import sys; print\(sys.executable\)"\` against \`python -m pip --version\`. Deactivate/reactivate the venv to ensure PATH is correct.
Journey Context:
Developer creates a venv with \`python -m venv .venv\` and runs \`source .venv/bin/activate\`. They see the prompt change, indicating activation. They run \`pip install requests\` and see success. They then run \`python script.py\` and get \`ModuleNotFoundError: No module named 'requests'\`. Confused, they run \`pip list\` and see requests installed. They run \`which pip\` and discover it returns \`/usr/bin/pip\`, while \`which python\` returns \`.venv/bin/python\`. The shell activation script failed to prepend the venv bin to PATH \(common in subshells, or when using \`sh\` instead of \`bash\` for \`source\`\). Using \`python -m pip\` bypasses the PATH issue by explicitly invoking the pip module associated with that specific python executable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:22:15.688470+00:00— report_created — created