Course Content
LangChain Mastery
7 sections · 109 lessons
How do you install LangChain and its dependencies?
What you need to know
LangChain used to be one big package that imported dozens of vendor SDKs. It is now split so you install only what you use.
1python -m venv .venv && source .venv/bin/activate2pip install -U langchain langchain-openai # core + one provider3pip install langchain-anthropic # a second provider, if needed4pip install langchain-text-splitters langchain-community pypdf # loaders, splitters5pip install langchain-postgres # pgvector store, if neededpip install langchainbringslangchain-core(the interfaces),langgraph(the agent runtime) andlangsmith(tracing) with it.- Each provider has its own package:
langchain-openai,langchain-anthropic,langchain-google-genai,langchain-ollama. langchain-communityholds the long tail of third-party integrations. Many popular ones have moved to their own packages, so check for a dedicated package first.langchain-classicis only for old code that still usesLLMChain,RetrievalQAand similar.
Keys and tracing
Keys never go in code or Git. Set them in the environment or load them from a secret manager:
1export OPENAI_API_KEY=...2export LANGSMITH_TRACING=true3export LANGSMITH_API_KEY=...4export LANGSMITH_PROJECT=support-bot-devWith those three LangSmith variables set, every chain and agent run is traced with no code change.
Pin versions
Provider packages release on their own schedule, and a mismatch with langchain-core is the usual cause of ImportError: cannot import name .... Pin exact versions with uv lock, poetry.lock or pip freeze > requirements.txt, and upgrade on purpose, with your tests running.
A real-life example
A Bengaluru real-estate firm is building a lead-qualification pipeline. The first developer ran pip install langchain in 2024 and copied old tutorials that imported from langchain.llms import OpenAI. After upgrading to LangChain 1.x in a new container, the service failed on start-up with ModuleNotFoundError. The fix took an hour: install langchain-openai, change the import to from langchain_openai import ChatOpenAI, pin all four LangChain packages in pyproject.toml, and add a CI job that runs the test suite on a weekly dependency-upgrade branch. Since then, upgrades are a reviewed pull request, not a surprise in production.
Follow-up questions to expect
- "Why is LangChain split into many packages?" — So you don't install every vendor SDK, and so a provider fix can ship without a full LangChain release.
- "What do you do when old tutorial code fails with
No module named 'langchain.chains'?" — Either installlangchain-classicand import fromlangchain_classic.chains, or better, rewrite the chain in LCEL. - "How do you manage keys in production?" — A secret manager (AWS Secrets Manager, Vault, GCP Secret Manager) injected as environment variables, never a
.envfile committed to Git.