LangChain Setup
LangChain setup takes a few minutes: create a virtual environment, install the packages you need, and start a model server. We use Ollama because it runs open-source models on your own machine with no API key and no cost per request.
Install Ollama and Pull Models
Download Ollama from ollama.com for Windows, macOS or Linux. After installing, it runs a local server on http://localhost:11434. Pull a chat model and an embedding model from a terminal:
ollama pull llama3.2
ollama pull nomic-embed-text
ollama listNAME SIZE llama3.2:latest 2.0 GB nomic-embed-text:latest 274 MB
llama3.2 is a small, capable chat model that supports tool calling. nomic-embed-text turns text into vectors, which you will need in the retrieval lessons. Other good choices are qwen3, mistral and gemma3.
Install the LangChain Packages
LangChain is split into small packages so you only install what you use. Create a virtual environment first:
python -m venv .venv
# Windows: .venv\Scripts\activate
source .venv/bin/activate
pip install -U langchain langchain-ollama langchain-chroma \
langchain-community langchain-text-splittersSuccessfully installed langchain-1.x langchain-core-1.x langchain-ollama-1.x ...
What Each Package Does
- langchain: main package with create_agent, init_chat_model and the tool decorator
- langchain-core: base abstractions (messages, prompts, runnables, output parsers); installed automatically
- langchain-ollama: ChatOllama and OllamaEmbeddings
- langchain-chroma: the Chroma vector store integration
- langchain-community: community document loaders and integrations
- langchain-text-splitters: tools for splitting long documents into chunks
Verify Your LangChain Setup
from langchain_ollama import ChatOllama
llm = ChatOllama(model="llama3.2")
print(llm.invoke("Reply with the single word: ready").content)Sample output: ready
If you see a connection error, Ollama is not running. Start the desktop app or run ollama serve in a terminal.
Using Hosted Providers Instead
To use a hosted model, install its integration package and set an API key as an environment variable, for example pip install langchain-openai and OPENAI_API_KEY, or langchain-anthropic and ANTHROPIC_API_KEY. Keep keys in a .env file and load them with python-dotenv; never hard-code them in source files. The rest of your code stays the same.
Frequently asked questions
Which Python version does LangChain need?
LangChain 1.x requires Python 3.10 or newer. Python 3.12 is a safe choice.
Do I need a GPU to run Ollama?
No. Small models run on a CPU, just more slowly. A GPU or Apple Silicon makes responses much faster.
Why does LangChain have so many packages?
Splitting integrations into separate packages keeps installs small and lets each integration be versioned and maintained independently.