Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

LlamaIndex cannot import Ollama from llama_index.llms

ErrorImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)

Short answer

Since LlamaIndex 0.10, each integration is its own package and the old top-level llama_index.llms path is gone. Install llama-index-llms-ollama and import Ollama from llama_index.llms.ollama. The model server must also be running, and slow models may need a longer request_timeout.

  • Applies to llama-index 0.10 and later, llama-index-llms-ollama, Ollama server, Python 3.10-3.13
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the installed LlamaIndex packages. The integration package must appear next to llama-index-core.

    python -m pip list | grep -i llama
  2. 2Match what you see, then jump to its fix

    1. 1The failing line is from llama_index.llms import OllamaOld import path from before the 0.10 package splitFix
    2. 2The new import path fails, while llama-index itself is installedThe Ollama integration package is not installedFix
    3. 3A timeout after about 30 seconds on a big model, or a connection error to localhost:11434The import works but the first call times out or cannot connectFix

What does the error look like?

  • ImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)

Cause 1 of 3

Old import path from before the 0.10 package split

1Check

The LlamaIndex 0.10 migration post says integrations became separate packages and that llama_index.llms can no longer be used as a top-level import.

grep -rn "from llama_index.llms import\|from llama_index import" --include='*.py' .

2Fix

Change the import to the namespaced path, or let the upgrade command rewrite the folder for you.

from llama_index.llms.ollama import Ollama

# or rewrite the whole source folder
llamaindex-cli upgrade ./src

3Verify

The import runs.

python -c "from llama_index.llms.ollama import Ollama; print('ok')"

Confirmed by llamaindex.ai

Did this fix it?

Cause 2 of 3

The Ollama integration package is not installed

1Check

The installation guide says pip install llama-index brings a starter bundle: core, OpenAI LLM and embeddings, and file readers. Ollama is not in it.

python -m pip show llama-index-llms-ollama

2Fix

Install the integration into the interpreter that runs your code.

python -m pip install llama-index-llms-ollama

3Verify

The package shows up and imports.

python -m pip show llama-index-llms-ollama

Confirmed by developers.llamaindex.ai

Did this fix it?

Cause 3 of 3

The import works but the first call times out or cannot connect

1Check

The LlamaIndex Ollama notebook says the default timeout is 30 seconds, and the class talks to the server at http://localhost:11434 unless you pass base_url. The server has to be running and the model pulled first.

ollama list
curl -s http://localhost:11434

2Fix

Start the server, pull the model, and raise request_timeout when constructing the class.

ollama serve
ollama pull llama3.1

# python
llm = Ollama(model="llama3.1:latest", request_timeout=120.0)

3Verify

A completion returns text.

print(llm.complete("Say hello in one word."))

Confirmed by developers.llamaindex.ai

Did this fix it?

How do I stop it coming back?

  • Install each LlamaIndex integration by name and keep core and integrations upgraded together.
  • Search new code and tutorials for from llama_index.llms import and fix it on sight.
  • Set request_timeout explicitly instead of relying on the 30-second default.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

AI

LangChain says it could not import the chromadb package

ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.

The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.