Why you need separate packages and which to install
Why this matters
Installing the wrong packages or missing dependencies will cause cryptic import errors in production. Understanding the split saves debugging time and keeps your dependency tree clean and auditable.
Explanation
What it is: LangChain is now distributed as a modular ecosystem. langchain-core contains the base abstractions and expression language. langchain is the main orchestration package. Every integration (OpenAI, Anthropic, Pinecone, etc.) lives in its own separate package like langchain-openai or langchain-anthropic. How it works: When you import from langchain_openai, it only works if that package is installed. The core framework doesn't know or care about OpenAI's API: that knowledge lives in the separate provider package. This design prevents you from downloading the entire universe of integrations when you only use 2. When to use it: Always structure your dependencies this way in production. Install langchain, install langchain-core if you're building custom components, and install only the provider packages you actually call.
Analogy
It's like installing a car engine (langchain-core), a chassis (langchain), and then buying only the specific wheels you need (langchain-openai, langchain-anthropic) instead of receiving a warehouse of every tire size ever made.
Code
import subprocess
import sys
# Show what's actually installed and what's needed
print("Step 1: Check if langchain-openai is installed")
try:
import langchain_openai
print(f"✓ langchain-openai is installed: {langchain_openai.__version__}")
except ImportError as e:
print(f"✗ langchain-openai is NOT installed")
print(f" Error: {e}")
print("\nStep 2: Try to import ChatOpenAI (requires langchain-openai package)")
try:
from langchain_openai import ChatOpenAI
print("✓ ChatOpenAI imported successfully")
except ImportError as e:
print(f"✗ Cannot import ChatOpenAI: {e}")
print(f" Fix: pip install langchain-openai")
print("\nStep 3: Import from langchain-core (always available)")
try:
from langchain_core.prompts import ChatPromptTemplate
print("✓ ChatPromptTemplate imported successfully (from langchain-core)")
except ImportError as e:
print(f"✗ Cannot import: {e}")
print("\nStep 4: Show the package structure")
import langchain
import langchain_core
print(f"langchain version: {langchain.__version__}")
print(f"langchain-core version: {langchain_core.__version__}")
print("\nMinimal production setup:")
print(" pip install langchain langchain-core langchain-openai") Step 1: Check if langchain-openai is installed ✗ langchain-openai is NOT installed Error: No module named 'langchain_openai' Step 2: Try to import ChatOpenAI (requires langchain-openai package) ✗ Cannot import ChatOpenAI: No module named 'langchain_openai' Fix: pip install langchain-openai Step 3: Import from langchain-core (always available) ✓ ChatPromptTemplate imported successfully (from langchain-core) Step 4: Show the package structure langchain version: 1.2.4 langchain-core version: 0.3.8 Minimal production setup: pip install langchain langchain-core langchain-openai
What just happened?
The code tried to import a provider-specific class (ChatOpenAI) that lives in a separate package (langchain-openai). Since that package isn't installed, Python raised ImportError. Then it successfully imported from langchain-core, which is part of the base installation. This demonstrates the package boundary: core abstractions are always available, provider integrations are optional.
Common gotcha
Developers often install just pip install langchain and then wonder why from langchain_openai import ChatOpenAI fails. They assume everything is in one package. The error message says 'No module named langchain_openai': which is correct, but feels like a bug. It's not. You need the separate provider package.
Error recovery
ModuleNotFoundError: No module named 'langchain_openai'ModuleNotFoundError: No module named 'langchain_anthropic'ImportError: cannot import name 'ChatOpenAI' from 'langchain'Experienced dev note
Pin versions explicitly in requirements.txt: langchain==1.2.4, langchain-core==0.3.8, langchain-openai==0.2.3. The ecosystem evolves fast: mismatched versions between core and providers cause subtle bugs. Also: don't install every langchain-* package 'just in case.' Each one brings its own dependencies. A minimal chatbot needs exactly 3 packages: langchain, langchain-core, and one provider. That's it. Everything else is weight.
Check your understanding
You have a project that uses OpenAI for LLMs and Pinecone for vector search. What packages must be in your requirements.txt, and why can't you just install langchain and call it done?
Show answer hint
A correct answer names the specific packages (langchain, langchain-core, langchain-openai, langchain-pinecone) and explains that each provider has its own package containing the API client logic and integration code that langchain-core doesn't include. Just installing langchain alone doesn't bring in those provider dependencies.