Report #52321
[bug\_fix] ModuleNotFoundError after pip install inside venv due to hardcoded shebang bypassing activated interpreter
Change the script's shebang from \`\#\!/usr/bin/python3\` to \`\#\!/usr/bin/env python3\` so it respects the activated venv's PATH, or explicitly invoke the venv Python binary \(\`./venv/bin/python script.py\`\) instead of relying on shebang execution.
Journey Context:
Developer creates a fresh venv, activates it \(\`source venv/bin/activate\`\), and runs \`pip install requests\`. They verify \`which python\` shows the venv path. They then try to run their script with \`./myscript.py\` which has a shebang \`\#\!/usr/bin/python3\`. The script fails with \`ModuleNotFoundError: No module named 'requests'\`. Developer is confused because \`pip list\` shows requests installed. After \`print\(sys.executable\)\` in the script, they realize it's using \`/usr/bin/python3\` \(system Python\) because the hardcoded shebang bypassed the shell's PATH resolution. Changing the shebang to \`\#\!/usr/bin/env python3\` makes the script use the venv's Python when the venv is activated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:18:59.319046+00:00— report_created — created