This is one of the most common Python problems in VS Code. You install a package, but VS Code still shows errors like ModuleNotFoundError or Import could not be resolved.
The package is usually installed — just not in the Python environment VS Code is using.
Fix 1 — Select the correct Python interpreter
- Open VS Code.
- Press Ctrl + Shift + P.
- Search for Python: Select Interpreter.
- Select the Python version where your package is installed.
- Restart VS Code.
This fixes the issue most of the time. VS Code can’t detect packages from an interpreter it isn’t using. Simple villain, big headache.
Fix 2 — Check which Python terminal is using
Open the VS Code terminal and run:
python --version
Then run:
where python
This shows which Python installation is active. If it points to a different location than expected, VS Code is using the wrong Python.
Fix 3 — Install the package in the active environment
Instead of installing randomly, use this command inside the VS Code terminal:
python -m pip install package-name
Example:
python -m pip install pandas
This makes sure the package installs into the Python environment currently being used.
Fix 4 — If using virtual environment
If your project uses a virtual environment, activate it first.
For Windows:
.venv\Scripts\activate
Then install the package:
python -m pip install pandas
Fix 5 — Restart the language server
Sometimes the package is installed correctly, but VS Code still shows a red underline. Restarting the Python language server can fix that.
- Press Ctrl + Shift + P.
- Search Python: Restart Language Server.
- Run it.
- If needed, restart VS Code.
Common reasons this happens
- VS Code selected the wrong Python interpreter.
- The package was installed globally, but the project uses a virtual environment.
- The package was installed for Python 3.11, but VS Code uses Python 3.12.
- The terminal and editor are using different Python paths.
- The VS Code Python extension needs a restart.
FAQ
Why does pip say installed but VS Code says missing?
Because pip may have installed the package in a different Python environment than the one VS Code is using.
Should I use virtual environments?
Yes. Virtual environments keep project packages clean and reduce version conflicts.
Will reinstalling VS Code fix this?
Usually no. The problem is normally Python environment selection, not VS Code itself.
VS Code & Python troubleshooting directory
Choose the symptom that most closely matches what you see:
- “Python was not found” — repair installation, PATH, or Windows app execution aliases.
- Python interpreter not showing — restore interpreter discovery and selection.
- pip command not found — run pip through the correct Python and repair PATH.
- ModuleNotFoundError — match the installed package to the interpreter running your file.
- Virtual environment not working — activate, select, or recreate the project environment.
- Pylance not working — repair language-server analysis and unresolved imports.
- Python IntelliSense not working — restore autocomplete, hints, and navigation.