Report #82362
[bug\_fix] ModuleNotFoundError in VS Code terminal despite package being installed in venv
Select the correct Python interpreter in VS Code \(Ctrl\+Shift\+P or Cmd\+Shift\+P, type "Python: Select Interpreter", choose the venv path\), or manually activate the venv in the terminal before running Python. The root cause is that VS Code's integrated terminal may launch with a different PATH or PYTHONPATH than the activated venv, causing the global Python interpreter \(which lacks the installed packages\) to be invoked instead of the venv's Python.
Journey Context:
You create a venv with \`python3 -m venv .venv\`, activate it with \`source .venv/bin/activate\`, and run \`pip install requests\`. You verify with \`python -c "import requests; print\('ok'\)"\` in the terminal and it works. You open VS Code in the project folder. You open a new integrated terminal and run \`python script.py\` which imports requests. You get \`ModuleNotFoundError: No module named 'requests'\`. You run \`which python\` and it shows \`/usr/bin/python\` instead of \`.venv/bin/python\`. You realize VS Code didn't auto-activate the venv in this specific terminal session. You click the Python version displayed in the VS Code status bar at the bottom-left, select the interpreter pointing to \`.venv/bin/python\`, close and reopen the integrated terminal, and now \`which python\` points to the venv and the import succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:50:15.907996+00:00— report_created — created