Learn/LangChain Mastery/Part 1 · 0. Intro & Setup
Lesson 2 of 68
SyllabusLangChain Mastery · Part 1

Setup & Installation

Comprehensive guide to Environment Setup in LangChain.

Course outline & contents
LangChain Mastery
IntroductionSetup & InstallationEvolution of AI Agents

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.

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

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

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:

.env
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="AIza..."

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)

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