Fundamentals

How to Install Python for AI on Windows

Install Python 3.10+ on Windows for AI work: download from python.org, add to PATH, verify in PowerShell, create a virtual environment, and install AI packages.

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."

The Add python.exe to PATH checkbox decision Ticking Add python.exe to PATH during install makes the python command work everywhere, while leaving it unticked causes a not-recognized error. python.org installer screen Add python.exe to PATH? Ticked python works in every folder Unticked "python is not recognized" errors
One checkbox decides whether the python command works everywhere or fails on first use.

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.

It helps to picture the four layers you now have on the machine. Windows finds python.exe through PATH, the python.org install provides the interpreter, .venv wraps a private copy of it for this one project, and your AI packages sit on top of that private copy — never in the system install.

The four layers of a Windows Python setup for AI work A stack of four layers: Windows and PATH at the base, the system Python install above it, the project's .venv folder above that, and the AI packages on top, showing that pip installs land inside the project rather than in the system install. Your AI packages openai, httpx, dotenv .venv folder private copy of Python System Python python.org install Windows and PATH finds python.exe
Activating the environment redirects pip to the top two layers, which is why the (.venv) prefix decides where a package actually lands.

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 .env file 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_dotenv()  # loads OPENAI_API_KEY from the .env file into the environment

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.

Follow the round trip that just happened, because the same four hops sit behind every AI script you will write on this machine.

What happens when you run verify_setup.py A four-step round trip: the script runs inside the activated environment, load_dotenv reads the key out of the .env file, the OpenAI client sends the prompt to the API, and the model's reply is printed back in PowerShell. verify_setup.py run inside (.venv) load_dotenv() reads .env secrets OpenAI API gpt-4o-mini replies PowerShell prints Windows setup verified
Each hop can fail on its own, so the printed line is proof that all four — environment, secret, network call, and reply — worked together.

With the round trip working, the last piece of a comfortable Windows setup is somewhere to write the code: Choose a Code Editor for Python AI Work compares the usual options and shows how to point each one at the .venv you just made.

Quick reference

Keep this table handy while you work on Windows.

CommandWhat it doesNotes
python --versionprints the installed Python versionmust read 3.10 or higher
py --versionruns the py launcherreliable fallback if PATH is broken
python -m venv .venvcreates a virtual environmentnamed .venv inside the project folder
.venv\Scripts\Activate.ps1activates the environmentneeds RemoteSigned execution policy
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedallows local scripts to runrun once to unblock activation

Troubleshooting

These are the exact errors Windows beginners hit most, with the cause and a one-line fix.

  1. '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, use py instead of python.
  2. Activate.ps1 cannot be loaded because running scripts is disabled on this system. PowerShell blocks scripts by default for security. Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, answer Y, then run the activation command again.
  3. The version command works but pip does not. pip is present but not on your PATH. Use python -m pip install <package> (or py -m pip install <package>), which calls pip through Python directly and always works.
  4. ModuleNotFoundError: No module named 'openai'. You installed the package outside the active environment. Confirm (.venv) shows in your prompt, then re-run pip install openai httpx python-dotenv. If it persists after that, Fix ModuleNotFoundError: No Module Named openai walks through the rarer causes, such as two Pythons on the same PATH.
  5. OPENAI_API_KEY loads as None even 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 .env with no extension.
  6. SSL: CERTIFICATE_VERIFY_FAILED. Common on work laptops, where security software inspects HTTPS traffic and your Python does not trust its certificate. Start with Fix SSL: CERTIFICATE_VERIFY_FAILED in Python, and test on a home network first to confirm the corporate proxy is the cause.

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 py launcher, 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 — How to Install Python for AI on Linux applies almost line for line once WSL is running. 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.

Side by side, the trade-off is easier to weigh: each route buys you something and charges you something else.

Three ways to get Python onto Windows, compared A three-row comparison matrix listing the python.org installer, the Microsoft Store package and WSL, with what each is best for and the trade-off each one carries. Option Best for Trade-off python.org installer Real AI projects py launcher + PATH Manual updates you tick the PATH box Microsoft Store one-click install Casual learning updates itself Sandboxed files venv paths confuse WSL Linux inside Windows Matching a server Linux-only wheels New shell to learn two file systems
Read each row left to right: the python.org installer costs you one checkbox and a manual upgrade, and buys the fewest surprises later.

If you are on a Mac instead, follow How to Install Python for AI Projects on Mac.

Back to Setting Up Python for AI.

Frequently asked questions

Which Python version should I install on Windows for AI?

Install the latest stable Python 3.10 or newer from python.org. The openai SDK and most current AI libraries dropped support for Python 3.9 after it reached end-of-life in October 2025, so do not pick anything older than 3.10.

Why does Windows say python is not recognized?

Windows cannot find Python on your PATH, the list of folders it searches for commands. This almost always means the Add python.exe to PATH box was left unticked during install. Re-run the installer, choose Modify, and enable that option, then open a fresh PowerShell window.

Should I install Python from the Microsoft Store or python.org?

For AI work, use the installer from python.org. It gives you the py launcher, full control over the install location, and the Add to PATH checkbox. The Microsoft Store version is fine for casual learning but sandboxes file access in ways that can confuse virtual environments and package installs.

How do I activate a virtual environment in PowerShell?

Run .venv\Scripts\Activate.ps1 from your project folder. If PowerShell blocks it with a script execution error, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, then activate again.

Do I need administrator rights to install Python on Windows?

No. The python.org installer can install just for your user account without admin rights. Untick Install for all users if you do not have an administrator password, and Python will install into your user folder instead.