Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 1 · 0. Intro & Setup
Lesson 2 of 68

Setup & Installation

Comprehensive guide to Environment Setup in LangChain.

Derpx065 Jan · 1 min read
LangChain Mastery
IntroductionSetup & InstallationEvolution of AI Agents
Contents
Project SetupOptional: Installing Ollama (Local Models)Environment ConfigurationBasic ExampleSummary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
IntroductionSetup & InstallationEvolution of AI Agents
Contents
Project SetupOptional: Installing Ollama (Local Models)Environment ConfigurationBasic ExampleSummary

In this lesson, we will cover how to set up your environment for building LangChain applications. We'll verify everything is working by installing the necessary packages, configuring your API keys, and running a simple completion.

Project Setup

First, let's create a directory for our project.

terminal
mkdir my-langchain-app
cd my-langchain-app

Now, we need to set up a virtual environment and install LangChain. You can choose between the standard Python tools or the modern uv package manager.

Code

Optional: Installing Ollama (Local Models)

If you want to run models locally (free & private), you need to install Ollama.

Code

Once installed, you can talk to the model directly in your terminal to verify it works:

Code

Environment Configuration

To use LLMs like OpenAI's GPT-4 or Google's Gemini, you need to set your API keys as environment variables. This creates a secure way for the LangChain library to access your credentials without hardcoding them in scripts.

Get your API keys here:

  • OpenAI: platform.openai.com/api-keys
  • Anthropic: console.anthropic.com/settings/keys
  • Google Gemini: aistudio.google.com/app/apikey
.env
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="AIza..."

Basic Example

Now that we have the library installed and the environment configured, let's run a simple script to verify our setup. We'll initialize a Chat Model and ask it a question.

test_setup.py
from langchain_openai import ChatOpenAI
# Or for Google Gemini:
# from langchain_google_genai import ChatGoogleGenerativeAI

# Initialize the model
llm = ChatOpenAI()
# llm = ChatGoogleGenerativeAI(model="gemini-pro")

# Invoke the model
response = llm.invoke("Hello, how are you?")

print(response.content)

Summary

You have now successfully:

  1. Created a project directory and virtual environment.
  2. Installed LangChain and integration packages (OpenAI, Google) using pip or uv.
  3. Configured your API keys.
  4. Verified the setup with a simple Python script.

You are ready to start building!

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonIntroductionNext lesson →Evolution of AI Agents