Report #11851
[bug\_fix] ModuleNotFoundError: No module named 'X' \(interpreter mismatch\)
Ensure the Python interpreter used to run the script is the same one associated with the virtual environment where packages were installed. Run \`which python\` \(or \`where python\` on Windows\) and \`which pip\` to verify they point to the venv's \`bin/\` \(or \`Scripts/\`\) directory. If they differ, activate the venv with \`source venv/bin/activate\` \(Linux/macOS\) or \`venv\\Scripts\\activate\` \(Windows\), or explicitly use the venv's Python binary: \`./venv/bin/python script.py\`.
Journey Context:
You create a new project with \`python3 -m venv venv\`, activate it, and \`pip install requests\`. You write \`script.py\` using \`import requests\` and try to run it in VS Code. You get \`ModuleNotFoundError: No module named 'requests'\`. Confused, you check \`pip list\` in the terminal and see \`requests\` is definitely there. You notice in VS Code's bottom-left status bar it says "Python 3.11.2 \(system\)". You open a terminal and type \`which python\` and it returns \`/usr/bin/python\`, not \`~/project/venv/bin/python\`. You realize that while you activated the venv in one terminal, VS Code and other shells are still using the system Python. You run \`source venv/bin/activate\` in the current terminal and then \`python script.py\` works because \`sys.path\` now includes the venv's \`site-packages\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:24:20.285729+00:00— report_created — created