This guide shows you how to install Python 3.10 or newer on Windows and get it ready for AI work in under fifteen minutes. By the end you will have Python on your PATH, a verified install in PowerShell, an isolated virtual environment, and the core AI packages installed and ready to call a model.
Windows has one quirk that trips up almost every beginner: a single checkbox in the installer decides whether the python command works at all afterwards. Get that one detail right and the rest is straightforward copy-and-paste. This guide is part of the Setting Up Python for AI section, which covers the same ground for every operating system.
Prerequisites
This guide assumes only what is specific to Windows. You need:
- Windows 10 or 11 with an internet connection to download Python and packages.
- PowerShell, which ships with every modern Windows install. Click Start, type
PowerShell, and press Enter to open it. PowerShell is the text window where you type one command at a time and press Enter. It will not damage anything, and the worst a typo does is show an error you can read and fix. - (For later AI work only) an API key. An API key is a secret password that lets your script call a paid or free-tier model. You can generate one at platform.openai.com/api-keys, or compare no-cost options in Best Free AI APIs for Beginners.
You do not need a programming background or administrator rights. Every command below is something you copy, paste into PowerShell with Ctrl+V, and run.
Step 1: Download and run the python.org installer
Open python.org/downloads in your browser. The site detects Windows and shows a yellow Download Python 3.x.x button for the latest stable release. Click it to download the 64-bit installer, then double-click the downloaded .exe file to launch it.
The first installer screen is the only one that matters, and it is where most beginners go wrong. Before you click anything, tick the box labeled "Add python.exe to PATH" at the bottom of the window. This single checkbox is what lets you type python in any folder and have Windows find it. If you skip it, every later command in this guide fails with "python is not recognized."
With the box ticked, click Install Now. Accept the User Account Control prompt if it appears, wait for the progress bar to finish, and click Close. If the final screen offers a "Disable path length limit" button, click it — it removes an old Windows restriction that can break deeply nested package paths. Your install is now complete; the next step proves it.
Step 2: Verify the install in PowerShell
Open a fresh PowerShell window after the install finishes. This matters: PowerShell reads its list of available commands once when it opens, so a window you had open before installing Python will not see it yet. Close any old windows and open a new one from the Start menu.
Now confirm the version:
python --version
pip --version
You should see something like Python 3.12.4 and a pip version line. pip is the tool that installs Python packages, and it ships with Python automatically. The version must start with 3.10 or higher; if it does, you are ready for the next step.
Windows also installs the py launcher, a small helper that finds and runs your Python versions for you. Confirm it works too:
py --version
py -0
The first line prints the default Python version; the second lists every Python the launcher can see. The py command is useful because it always works even when the bare python command does not, which makes it a reliable fallback if your PATH is ever misconfigured. If python --version fails but py --version works, jump to the troubleshooting section — your PATH needs fixing, and the py launcher is your bridge in the meantime.
Step 3: Create and activate a virtual environment
A virtual environment is a private copy of Python and its packages that lives inside one project folder. It stops different projects from fighting over package versions and keeps your main install clean. You build one with a single command. The Create a Python Virtual Environment for AI guide covers the concept in depth; here is the Windows-specific version.
Make a project folder, move into it, and create the environment:
mkdir ai-workspace
cd ai-workspace
python -m venv .venv
The python -m venv .venv command builds a small private copy of Python inside a folder called .venv. Creating it is not the same as using it — you must activate it so that python and pip point at the private copy:
.venv\Scripts\Activate.ps1
After activation, your prompt shows a (.venv) prefix — visual proof that you are inside the isolated environment. If PowerShell instead shows a red error about scripts being disabled, that is the execution policy blocking the activation script; the troubleshooting section below has the one-line fix. When you finish for the day, type deactivate to step back out.
Get into the habit of checking for that (.venv) prefix before you run any pip install. The most common reason a package seems "missing" later is that it was installed while the environment was inactive, so it landed in your main Python instead.
Step 4: Install the AI packages
With (.venv) showing in your prompt, install the core toolkit. We use the official openai SDK and httpx (a modern HTTP library) rather than the older requests, because the SDK depends on httpx under the hood and handles authentication, retries, and timeouts for you:
pip install openai httpx python-dotenv
Here is what each package does:
openai— the official SDK for calling OpenAI models with one clean function call.httpx— the HTTP engine the SDK uses to reach the API; you rarely call it directly but it must be present.python-dotenv— loads secrets such as your API key from a.envfile so they never get hard-coded into your scripts.
Once the install finishes, lock the exact versions into a requirements.txt file so the setup is reproducible on any other machine:
pip freeze > requirements.txt
To restore those versions elsewhere, you would run pip install -r requirements.txt inside a fresh activated environment. Next, store your API key safely. Create a file named .env in your project root with one line:
OPENAI_API_KEY=sk-your-real-key-here
Immediately tell Git to ignore that file so your secret never gets committed:
Add-Content .gitignore ".env"
Always add .env to .gitignore before your first commit — a leaked API key can run up real charges on your account. Watch one Windows trap here: Notepad and File Explorer can silently save the file as .env.txt, which load_dotenv() will never find. To learn how the key authenticates each request, read Understanding LLM APIs.
Step 5: Run a quick verification
Confirm every layer works together. Create a file named verify_setup.py in your project root:
import os
from dotenv import load_dotenv
from openai import OpenAI
# Load OPENAI_API_KEY from the .env file into the environment
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Reply with exactly: Windows setup verified."},
],
max_tokens=10,
)
print(response.choices[0].message.content)
Run it from your activated environment:
python verify_setup.py
If you see Windows setup verified. printed in PowerShell, every layer is working: Python is installed and modern, the virtual environment is active, the openai SDK imported cleanly, your .env file loaded, and your key was accepted by a live model.
Quick reference
Keep this table handy while you work on Windows.
| Command | What it does | Notes |
|---|---|---|
python --version | prints the installed Python version | must read 3.10 or higher |
py --version | runs the py launcher | reliable fallback if PATH is broken |
python -m venv .venv | creates a virtual environment | named .venv inside the project folder |
.venv\Scripts\Activate.ps1 | activates the environment | needs RemoteSigned execution policy |
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned | allows local scripts to run | run once to unblock activation |
Troubleshooting
These are the exact errors Windows beginners hit most, with the cause and a one-line fix.
'python' is not recognized as an internal or external command. Python is not on your PATH because the Add python.exe to PATH box was left unticked. Re-run the installer, choose Modify, tick the option, and open a fresh PowerShell window. In the meantime, usepyinstead ofpython.Activate.ps1 cannot be loaded because running scripts is disabled on this system. PowerShell blocks scripts by default for security. RunSet-ExecutionPolicy -Scope CurrentUser RemoteSignedonce, answerY, then run the activation command again.- The version command works but
pipdoes not. pip is present but not on your PATH. Usepython -m pip install <package>(orpy -m pip install <package>), which calls pip through Python directly and always works. ModuleNotFoundError: No module named 'openai'. You installed the package outside the active environment. Confirm(.venv)shows in your prompt, then re-runpip install openai httpx python-dotenv.OPENAI_API_KEYloads asNoneeven though the file exists. Notepad saved the file as.env.txt. In File Explorer, enable File name extensions under the View menu, then rename the file to exactly.envwith no extension.
When to use this vs. alternatives
There are three common ways to get Python on Windows, and the right one depends on how you plan to work.
- python.org installer (this guide): the best default for AI work. You get the
pylauncher, the Add to PATH checkbox, full control over the install location, and a setup that matches almost every tutorial you will read. Choose this unless you have a specific reason not to. - Microsoft Store: convenient for casual learning and auto-updates, but it sandboxes file access in ways that occasionally confuse virtual environments and package installs. It also omits some launcher behavior. Fine for a first taste of Python; switch to the python.org installer once you start building real projects.
- WSL (Windows Subsystem for Linux): runs a full Linux environment inside Windows, so you follow Mac/Linux instructions instead. Pick this if you want your machine to mirror a Linux server you will deploy to, or if a library only ships Linux wheels. It adds a learning curve, so it suits developers comfortable with a Linux shell more than first-time beginners.
If you are on a Mac instead, follow How to Install Python for AI Projects on Mac.
Back to Setting Up Python for AI.