Code Beginner easy · 5 min

Installing llama-index and required packages

What you will learn
Set up llama-index-core and its essential dependencies in a Python environment.

Why this matters

You cannot build anything with llama-index until the packages are installed correctly. A misconfigured environment causes cryptic import errors that waste debugging time. Getting this right the first time unblocks every subsequent lesson.

Skip if: You don't need to follow this if you're using a pre-built Docker container or cloud environment (AWS SageMaker, Google Colab) that already has llama-index installed. You also don't need this if you're only reading llama-index documentation without running code locally.

Explanation

llama-index-core is the foundational package for building retrieval-augmented generation (RAG) applications. It provides vector stores, document loaders, and LLM integrations. When you install it, you get the core framework, but you need additional packages for specific integrations: OpenAI for GPT models, Pinecone for vector storage, or Ollama for local LLMs. How it works mechanically: pip fetches the packages from PyPI, resolves their dependencies (including transitive ones like pydantic, httpx, nest-asyncio), and installs them into your Python environment's site-packages directory. Version conflicts between dependencies can cause silent failures where imports succeed but behavior is broken. When to use this approach: Always start here before your first llama-index project. Use a virtual environment (venv or conda) to isolate packages per project: never install globally into your system Python.

Analogy

Installing packages is like setting up a construction site. llama-index-core is the main toolbox, but you also need specialized tool kits (OpenAI wrench, Pinecone measuring tape). If you don't install the right tools, your blueprints won't execute. A virtual environment is your isolated job site so one project's tools don't interfere with another's.

Code

python
#!/usr/bin/env python3
import subprocess
import sys
import json

packages_to_install = [
    'llama-index-core>=0.12.0',
    'llama-index-llms-openai>=0.1.0',
]

print('Installing llama-index packages...')
for package in packages_to_install:
    result = subprocess.run(
        [sys.executable, '-m', 'pip', 'install', package],
        capture_output=True,
        text=True
    )
    if result.returncode == 0:
        print(f'✓ Successfully installed {package}')
    else:
        print(f'✗ Failed to install {package}')
        print(f'Error: {result.stderr}')
        sys.exit(1)

print('\nVerifying installation...')
try:
    from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
    from llama_index.llms.openai import OpenAI
    print('✓ llama-index-core imports successful')
    print('✓ OpenAI integration imports successful')
    print(f'\nllama-index-core version: {__import__("llama_index.core").__version__}')
except ImportError as e:
    print(f'✗ Import failed: {e}')
    sys.exit(1)

print('\n✓ All packages installed and verified successfully!')
Output
Installing llama-index packages...
✓ Successfully installed llama-index-core>=0.12.0
✓ Successfully installed llama-index-llms-openai>=0.1.0

Verifying installation...
✓ llama-index-core imports successful
✓ OpenAI integration imports successful

llama-index-core version: 0.12.8

✓ All packages installed and verified successfully!

What just happened?

The code used pip to install two packages: the core llama-index framework and the OpenAI integration. After installation, it imported the key modules to verify they're accessible. The version check confirms that a compatible version of llama-index-core is installed. If any step failed, the script exits with an error code so you can see exactly where the installation broke.

Common gotcha

Many developers install llama-index (the old 0.1.x package) instead of llama-index-core. The old package is deprecated and incompatible with modern code. You'll get confusing import errors like ModuleNotFoundError: No module named 'llama_index.core' because the old package has a different structure. Always install llama-index-core, not llama-index.

Error recovery

ModuleNotFoundError: No module named 'llama_index.core'
You installed the wrong package. Run `pip uninstall llama-index` then `pip install llama-index-core>=0.12.0`. The old llama-index package (< 0.3.0) has a completely different API.
pip: command not found
Python or pip is not in your PATH. Use `python3 -m pip install llama-index-core>=0.12.0` instead, or verify Python is installed with `python3 --version`.
error: ERROR: Could not find a version that satisfies the requirement
You specified a version that doesn't exist or your pip cache is stale. Run `pip install --upgrade pip` then try again. If that fails, run `pip install llama-index-core` without a version specifier.
PermissionError: [Errno 13] Permission denied
You're installing globally into system Python. Create a virtual environment first: `python3 -m venv llama_env` and activate it before installing packages.

Experienced dev note

Always use a virtual environment: never skip this step, even for 'quick' projects. A version conflict from a previous project can silently break new code. The pattern `[sys.executable, '-m', 'pip', 'install', ...]` is more reliable than calling `pip` directly because it uses the correct Python interpreter. If you're on a team, add a `requirements.txt` with pinned versions (e.g., `llama-index-core==0.12.8`) so everyone runs the exact same code. The difference between `>=0.12.0` (any version 0.12 or newer) and `==0.12.8` (only this version) matters in production: use pinned versions in requirements.txt, flexible versions only during exploration.

Check your understanding

You just installed llama-index-core successfully and verified the import. Now, if a colleague asks 'Why can't I import llama_index.core after running pip install llama-index?' what is the most likely reason, and what's the exact fix?

Show answer hint

A correct answer identifies that they installed the deprecated `llama-index` package (the old 0.1.x version) instead of `llama-index-core`, and the fix is to uninstall the wrong package and install the correct one. Simply running pip install again won't work: the old package has to be removed first.

VERSION llama-index had a major API reorganization in version 0.3.0 (released mid-2024). The old import `from llama_index import ...` stopped working; all imports now come from `llama_index.core`. If you see tutorials using the old import style, they're for llama-index < 0.3.0 and won't work with llama-index-core 0.12.x.
NEXT

Learn how to configure the OpenAI LLM and set global settings so your llama-index code can actually call an AI model.

Community Notes

No notes yetBe the first to share a version-specific fix or tip.