Report #22615
[bug\_fix] ModuleNotFoundError due to venv interpreter mismatch
Ensure the Python interpreter being executed is the one from the virtual environment by using the explicit path \(./venv/bin/python\) or activating the environment \(source venv/bin/activate\). If using scripts installed by pip entry points, ensure shebangs were generated pointing to the venv interpreter, reinstall with \`pip install --force-reinstall --no-deps package\` to regenerate entry points if the venv was moved.
Journey Context:
You create a venv with python3 -m venv myenv, activate it \(source myenv/bin/activate\), and pip install requests. You write a script with \#\!/usr/bin/env python3 and run ./myscript.py. It fails with ModuleNotFoundError. You check pip list and see requests is there. You print\(sys.executable\) inside the script and discover it's /usr/bin/python3, not myenv/bin/python3. The shebang \#\!/usr/bin/env python3 finds the system python first in PATH before the activated venv \(or activation didn't modify PATH correctly, or you're running from cron/IDE that doesn't inherit activation\). The fix is changing the shebang to \#\!/usr/bin/env python and ensuring the venv is activated, or explicitly calling ./myenv/bin/python myscript.py, or using python -m module execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:22:05.471564+00:00— report_created — created