79734521

Date: 2025-08-13 16:19:54
Score: 3
Natty:
Report link

Title:

Why do I get Import "llama_index.xxx" could not be resolved in VS Code even though I installed it?


Question:

I’m using Python 3.11.8 in a virtual environment.
I installed llama-index and llama-parse successfully via pip.
My code runs fine, but in VS Code I get warnings for every import:

Import "llama_index.llms.ollama" could not be resolved
Import "llama_parse" could not be resolved
...

Example:

from llama_index.llms.ollama import Ollama
from llama_parse import LlamaParse
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, PromptTemplate

How can I fix this?


Answer:

This error is from VS Code’s Pylance, not Python.
It happens because VS Code is looking at a different Python environment than the one where you installed the packages.


1. Check if the packages are installed in your active environment

Open a terminal inside VS Code, activate your venv, and run:

# Linux / Mac
which python

# Windows
where python

python -m pip show llama-index llama-parse

If they’re missing, install them in that environment:

python -m pip install llama-index llama-parse

2. Select the correct Python interpreter in VS Code

  1. Press Ctrl + Shift + P (or Cmd + Shift + P on Mac)
  2. Search for: Python: Select Interpreter
  3. Choose the interpreter from your project’s .venv or env folder.

3. Restart VS Code and reload Pylance

Ctrl + Shift + P → Developer: Reload Window

Or disable and re-enable the Python extension.


4. Verify imports at runtime

python -c "import llama_index; import llama_parse; print('All good!')"

If it prints “All good!”, your runtime is fine — the warning was just an IntelliSense environment mismatch.


💡 Summary:
Your imports are correct, but VS Code was using the wrong Python environment.
Once you install the packages in the correct interpreter and select it in VS Code, the warnings will go away.

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Blacklisted phrase (1): How can I fix this
  • RegEx Blacklisted phrase (1.5): How can I fix this?
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: İbrahim Enes ULUSOY