ix ModuleNotFoundError in VS Code — 5 Causes and Fixes
ModuleNotFoundError in VS Code almost always means the wrong Python interpreter is selected, not a missing package. Here are the 5 causes and exact fixes — interpreter mismatch, wrong venv, missing __init__.py, and more.
What's Actually Happening
VS Code runs Python through a specific interpreter. If that interpreter isn't your virtual environment — or the package isn't installed in it — you get ModuleNotFoundError even when pip install looked like it worked.
Step 1: Check Which Python VS Code Is Using
Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P) → Python: Select Interpreter.
The interpreter shown in the bottom status bar is what VS Code uses to run your files. If it shows /usr/bin/python3 or a system Python instead of .venv/bin/python, that's the problem.
Fix: Select the interpreter that points to your virtual environment. Look for one with
.venvorvenvin the path.
Step 2: Verify Package Is Installed in the Right Environment
Warning: Running
pip installwithout activating the venv installs into your system Python. VS Code's venv interpreter won't find it. Always activate before installing.
Step 3: Fix Missing __init__.py for Local Modules
If the ModuleNotFoundError is about your own code (not a third-party package):
Fix: Add
__init__.pyto makeutils/a proper Python package.
Then run from the project root, not from inside a subdirectory:
Step 4: Check for Editable Install Issues
If you're developing a package and importing it by name:
Without -e, changes to your source files don't reflect in the installed package. With -e, Python imports directly from your source directory.
Step 5: VS Code Settings Override
Sometimes VS Code has a python.defaultInterpreterPath hardcoded in .vscode/settings.json that overrides your selection:
Fix: Update the path to your venv, or delete the setting and use Command Palette to select the interpreter.
Diagnostic Checklist
Common Cause Summary
| Symptom | Cause | Fix |
|---|---|---|
| Package installed but error persists | Wrong interpreter in VS Code | Select correct .venv interpreter |
pip install ran, still fails | Installed to system Python, not venv | Activate venv, reinstall |
| Error on your own module | Missing __init__.py | Add empty __init__.py |
| Works in terminal, fails in VS Code | VS Code using different Python | Check status bar interpreter |
| Works locally, fails in CI | Different environment | Check requirements.txt is complete |
For ModuleNotFoundError in complex monorepos or projects with custom package structure, paste the full error and your directory tree into DebugAI. It identifies whether the problem is interpreter mismatch, missing package, or broken import path.
Debug faster starting today.
Free VS Code extension. 10 sessions/day. No credit card.