Setup & EnvironmentLesson 3

Project Setup

OpenAI and Ollama are ready. This lesson installs Python, creates a virtual environment, and lays out the project folder LangChain will use. Same steps every time you start a small LLM script.

Install Python

LangChain runs on Python. This course uses 3.14.5. If python --version already shows 3.14.5, skip to verify below — otherwise download the installer.

PythonPSFDocsPyPIJobsCommunity
python
DonateSearchGOSocialize ▾
AboutDownloadsDocumentationCommunitySuccess StoriesNewsEvents

Download the latest version for Windows

Download Python install manager

Or get the standalone installer for Python 3.14.5

Looking for Python with a different OS? Python for Windows, Linux/Unix, macOS, Android, other

Want to help test development versions of Python 3.15? Pre-releases, Docker images

Active Python releases

For more information visit the Python Developer's Guide.

Python versionMaintenance statusFirst releasedEnd of support
3.14bugfix2025-10-07
3.13bugfix2024-10-07
3.12security2023-10-022028-10
2.7end-of-life2010-07-032020-01-01
Current layout at python.org/downloads. Download Python 3.14.5 via the yellow button or standalone installer.

Install Python 3.14.5 (64-bit)

CancelInstall Now
On Windows, tick Add python.exe to PATH on the first installer screen — easy to miss.
PowerShell — check install
PS C:\Users\you> python --version
Python 3.14.5
PS C:\Users\you> pip --version
pip 25.1 from … (python 3.14)
Open a new terminal after installing. If python is not found, reopen the installer and enable PATH, or reinstall with the checkbox on.

One folder for the course

Create langchain-course on your machine — Desktop, Documents, or anywhere you keep coding projects. Everything for the HTML tutorial helper from What is LangChain? will live inside this directory.

EXPLORER — langchain-courseVS Code
langchain-course/
.venv/
.env
.gitignore
requirements.txt
html_tutorial_helper.py
One folder for the whole course. html_tutorial_helper.py comes in a later lesson — create the empty file now if you like.

Or download the starter ZIP

Prefer not to create every file by hand? Download the zip below. It contains requirements.txt, a .env.example template, .gitignore, and a placeholder html_tutorial_helper.py. Unzip, then follow the venv and pip steps in the sections below.

langchain-course-starter.zip

Pre-built project files for this lesson

Download ZIP

Inside the archive

  • README.txt
  • requirements.txt
  • .env.example
  • .gitignore
  • hello_langchain.py
  • hello_ollama.py
  • model_params_demo.py
  • html_tutorial_helper.py
Unzip anywhere convenient, rename the folder to langchain-course if you like, then copy .env.example to .env.

Environment setup

Do not install LangChain globally on your PC. Use a virtual environment inside the project folder — a private copy of pip packages that stays with this course only.

Inside langchain-course, run the commands below. Activate the venv before every session; your prompt shows (.venv) when it is on.

StepWindows (PowerShell)macOS / Linux
Create venvpython -m venv .venvpython3 -m venv .venv
Activate.\.venv\Scripts\Activate.ps1source .venv/bin/activate
Deactivatedeactivate
PowerShell
PS C:\projects> mkdir langchain-course
PS C:\projects> cd langchain-course
PS C:\projects\langchain-course> python -m venv .venv
PS C:\projects\langchain-course> .\.venv\Scripts\Activate.ps1
(.venv) PS C:\projects\langchain-course> python --version
Python 3.14.5
On macOS/Linux, activate with source .venv/bin/activate. See venv docs.

Dependencies

Add a requirements.txt file listing what the scripts need. Install with pip while the venv is active.

requirements.txt
1 # LangChain course dependencies
2 langchain
3 langchain-openai
4 langchain-ollama
5 python-dotenv
Four packages: core LangChain, OpenAI connector, Ollama connector, and python-dotenv to read .env.
PowerShell — (.venv) active
(.venv) PS C:\projects\langchain-course> pip install -r requirements.txt
Collecting langchain…
Collecting langchain-openai…
Collecting langchain-ollama…
Collecting python-dotenv…
Successfully installed langchain-0.3.21 langchain-openai-0.3.9 …
Run this once per project while the virtual environment is active. Version numbers will differ — that is normal.

Secrets and Git

Copy your OpenAI key into .env. Add OLLAMA_BASE_URL now so switching to a local model later is a one-line change in code, not a hunt through old notes.

.env
# from OpenAI Account Setup
OPENAI_API_KEY=sk-proj-…
# optional — local Ollama default
OLLAMA_BASE_URL=http://localhost:11434
.gitignore
.venv/
.env
__pycache__/
*.pyc
Paste the key from OpenAI Account Setup. Never commit .env or .venv/.

Quick check

With the venv active, run pip show langchain — you should see a version line and the install path inside .venv. If that works, the project shell is ready. The next lesson adds hello_langchain.py — your first LangChain script that reads .env and calls OpenAI.

What's Next

Project folder, venv, and packages are set. Next: your first LangChain script.