LangChain and LlamaIndex are two of the most widely used frameworks in AI application development — but their rapid release cycles mean that code which worked perfectly last week can suddenly break after an update. If you've run into confusing ImportError, AttributeError, or pip dependency conflicts, you're not alone. This guide breaks down the five most common failure patterns and walks you through practical fixes.
Recognizing the Symptoms
Before diving into solutions, it helps to identify which type of error you're dealing with.
pip dependency conflict during installation
ERROR: pip's dependency resolver does not currently take into account
all the packages that are installed. This behaviour is the source of
the following dependency conflicts.
langchain 0.1.x requires openai>=1.6.1, but you have openai 0.28.0
which is incompatible.
ImportError from outdated module paths
from langchain.llms import OpenAI # old import path
# → ImportError: cannot import name 'OpenAI' from 'langchain.llms'This is one of the most frequent issues. LangChain restructured its package layout starting with v0.1, and many tutorials and books still reference the old import paths.
LlamaIndex AttributeError on class names
from llama_index import GPTSimpleVectorIndex # removed in v0.10
# → AttributeError: module 'llama_index' has no attribute 'GPTSimpleVectorIndex'LlamaIndex renamed its core classes in v0.10, dropping the GPT prefix and splitting the package into modular components.
Root Causes: 5 Common Patterns
Pattern 1: Code Written Against Older APIs
LangChain introduced breaking changes in v0.1 (early 2024) and again in v0.2 (mid-2024). Most online tutorials, courses, and books published before these releases use deprecated import paths and class names that no longer exist in current versions.
Pattern 2: openai Library Version Mismatch
LangChain v0.2 and later require openai>=1.6.1, but many older projects still have openai==0.28.x installed. The v0.x and v1.x versions of the openai library have completely different APIs, so simply upgrading LangChain without also updating openai will cause cascading errors.
Pattern 3: Mixed Virtual Environments
Running pip install without an active virtual environment installs packages globally, which can conflict with other projects. If your pip install seems to succeed but the old version still loads, this is almost always the culprit.
Pattern 4: LlamaIndex Monolithic Package Deprecated
Starting with v0.10, LlamaIndex split from a single llama_index package into llama-index-core plus many optional integration packages. Installing only pip install llama-index is no longer sufficient — you need to separately install connectors for your LLM, embeddings, and other components.
Pattern 5: Stale .egg-info or Editable Installs
If you previously installed a package in editable mode (pip install -e .), old .egg-info directories can cause Python to load the cached version even after reinstalling. This is especially common in long-running development environments.
Step-by-Step Solutions
Step 1: Audit Your Current Environment
Start by understanding exactly what you have installed and where.
# Confirm which Python is being used
which python
python --version
# Check installed versions of key packages
pip show langchain langchain-core langchain-community openai
pip show llama-index llama-index-core
# Confirm your virtual environment is active
echo $VIRTUAL_ENV # empty means you're in the global environmentStep 2: Create a Dedicated Virtual Environment
Isolating each project in its own virtual environment is the single most effective way to prevent dependency conflicts.
# Create a new virtual environment with venv
python -m venv .venv
source .venv/bin/activate # macOS / Linux
# .venv\Scripts\activate # Windows
# Alternatively, use uv for faster installs
pip install uv
uv venv
source .venv/bin/activateStep 3: Install LangChain Using the New Package Structure
Since v0.2, LangChain has been split into separate packages. Install only what you need.
# Minimal setup (LLM calls only)
pip install langchain-core langchain-openai
# With community tools and utilities
pip install langchain langchain-openai langchain-community
# Verify installation
python -c "import langchain; print(langchain.__version__)"
# Expected: 0.2.x or higherUpdate your import statements to match the new structure:
# ❌ Old API (pre-v0.1)
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.7)
# ✅ New API (v0.2+)
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o", temperature=0.7)Step 4: Install LlamaIndex with the Modular Packages
LlamaIndex v0.10+ requires installing the core package plus specific integration packages for your use case.
# Core package (required for all use cases)
pip install llama-index-core
# Add OpenAI LLM and embedding support
pip install llama-index-core llama-index-llms-openai llama-index-embeddings-openai
# Use Gemini instead
pip install llama-index-core llama-index-llms-gemini llama-index-embeddings-geminiMigrate your code to the updated class names:
# ❌ Old API (pre-v0.10)
from llama_index import GPTSimpleVectorIndex, Document
index = GPTSimpleVectorIndex([Document(text="hello")])
# ✅ New API (v0.10+)
from llama_index.core import VectorStoreIndex, Document
index = VectorStoreIndex.from_documents([Document(text="hello")])Step 5: Update the openai Library
LangChain v0.2 requires openai>=1.6. If you have an older version, upgrade it.
pip install --upgrade openai
python -c "import openai; print(openai.__version__)"
# Expected: 1.x.xVerifying Your Fix
Run the following script to confirm all packages are correctly installed and importable:
# verify_install.py
import sys
print(f"Python: {sys.version}")
try:
import langchain
print(f"✅ langchain: {langchain.__version__}")
except ImportError as e:
print(f"❌ langchain import failed: {e}")
try:
from langchain_openai import ChatOpenAI
print("✅ langchain_openai: OK")
except ImportError as e:
print(f"❌ langchain_openai import failed: {e}")
try:
from llama_index.core import VectorStoreIndex
print("✅ llama_index.core: OK")
except ImportError as e:
print(f"❌ llama_index.core import failed: {e}")
try:
import openai
print(f"✅ openai: {openai.__version__}")
except ImportError as e:
print(f"❌ openai import failed: {e}")python verify_install.py
# Expected output:
# Python: 3.11.x
# ✅ langchain: 0.2.x
# ✅ langchain_openai: OK
# ✅ llama_index.core: OK
# ✅ openai: 1.x.xPrevention: Best Practices Going Forward
Pin your dependencies in requirements.txt
# requirements.txt (example)
langchain==0.2.16
langchain-openai==0.1.23
langchain-community==0.2.16
llama-index-core==0.10.68
llama-index-llms-openai==0.1.29
openai==1.51.0Pinning versions ensures that anyone who clones your project — including your CI/CD pipeline — gets exactly the same environment you tested with.
Use Antigravity to automate migration
As discussed in our RAG Pipeline Setup Guide, Antigravity's AI agent can scan your entire codebase for deprecated API calls and suggest updated equivalents. For large-scale migrations across many files, this can save hours of manual work.
Monitor changelogs before upgrading
Both LangChain and LlamaIndex publish detailed changelogs on GitHub. Even minor version bumps occasionally include breaking changes, so reviewing the CHANGELOG before running pip install --upgrade is a habit worth forming.
Looking back
LangChain and LlamaIndex version errors are frustrating, but they follow predictable patterns that can be resolved systematically:
- Always use a dedicated virtual environment for each project
- Use the new subpackage structure:
langchain-core+langchain-openaifor LangChain - Install
llama-index-coreplus the specific integration packages you need - Make sure
openai>=1.6is installed when using LangChain v0.2+ - Pin versions in
requirements.txtto prevent future surprises
If you're also dealing with CUDA or PyTorch installation issues, our Python, PyTorch, and CUDA Installation Error Fix guide covers that environment in detail.