LangChain Mastery

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.

Bash
python -m venv .venv && source .venv/bin/activatepip install -U langchain langchain-openai         # core + one providerpip install langchain-anthropic                   # a second provider, if neededpip install langchain-text-splitters langchain-community pypdf   # loaders, splitterspip install langchain-postgres                    # pgvector store, if needed
  • pip install langchain brings langchain-core (the interfaces), langgraph (the agent runtime) and langsmith (tracing) with it.
  • Each provider has its own package: langchain-openai, langchain-anthropic, langchain-google-genai, langchain-ollama.
  • langchain-community holds the long tail of third-party integrations. Many popular ones have moved to their own packages, so check for a dedicated package first.
  • langchain-classic is only for old code that still uses LLMChain, RetrievalQA and similar.

Keys and tracing

Keys never go in code or Git. Set them in the environment or load them from a secret manager:

Bash
export OPENAI_API_KEY=...export LANGSMITH_TRACING=trueexport LANGSMITH_API_KEY=...export LANGSMITH_PROJECT=support-bot-dev

With 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 install langchain-classic and import from langchain_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 .env file committed to Git.