Python online course

Add Python to PATH on Windows

Learn how to add Python and its Scripts folder to the Windows PATH so python, pip, and version-specific commands work in Command Prompt and PowerShell.

When Python is installed on Windows, the interpreter may work only when you provide its complete installation path. Adding Python to the Windows PATH lets you run commands such as python and pip from Command Prompt or PowerShell.

This guide is for a common situation: Python is installed, but the installer option to add Python to PATH was not selected. For installation basics, see Install Python on Windows.

What PATH is and why Python needs it

PATH is a Windows environment variable. An environment variable is a named configuration value supplied to programs and command shells. PATH contains an ordered list of directories that Windows searches when you enter an executable command.

For example, when you type python, Windows searches the PATH directories for a matching executable, usually python.exe. If the directory containing that file is on PATH, you can run Python without typing a location such as C:\Users\YourName\AppData\Local\Programs\Python\Python312\python.exe.

The same principle applies to pip. The Python installation's Scripts directory commonly contains pip.exe and other command-line tools, so that directory may need its own PATH entry.

Check the current command behavior

Open a new Command Prompt by searching for Command Prompt in the Start menu. You can also open PowerShell by searching for PowerShell. The commands in this lesson work in either shell unless noted otherwise.

python --version
py --version
where python
where py
CommandPurposeTypical successful resultWhat a failure can indicate
python --versionChecks the unversioned Python command.Python 3.12.xPython is absent from PATH, or an alias is intercepting the command.
py --versionChecks the Windows Python Launcher.A launcher version or selected Python versionThe launcher was not installed, or no Python installation is registered with it.
where pythonLists matching python.exe locations found through PATH.One or more executable pathsNo PATH match, or Windows is resolving a different command mechanism.
where pyLocates the Python Launcher executable.A path to py.exeThe launcher is not available through PATH.

If Python is found, the version command prints its version. If the command is not recognized, Python's interpreter directory is probably missing from PATH, Python may not be installed, or the terminal may have been opened before a PATH change.

If typing python opens or suggests the Microsoft Store, Windows may be using an App Execution Alias. This is a Windows command alias that can redirect python to the Store; it does not necessarily mean that Python is missing.

Find the installed Python location

First, look for the folder that contains python.exe. Common per-user installations are under the signed-in user's local application directory:

C:\Users\YourName\AppData\Local\Programs\Python\Python312
C:\Users\YourName\AppData\Local\Programs\Python\Python313

Common all-users installations are under Program Files:

C:\Program Files\Python312
C:\Program Files\Python313

The exact folder name includes the installed version, such as Python312 or Python313. Do not assume the example version matches your installation.

Installation typeTypical interpreter directoryTypical Scripts directoryNotes
Per-userC:\Users\YourName\AppData\Local\Programs\Python\Python312C:\Users\YourName\AppData\Local\Programs\Python\Python312\ScriptsUsually does not require administrator permission.
All-usersC:\Program Files\Python312C:\Program Files\Python312\ScriptsMay require administrator permission to modify or repair.

The main interpreter directory is the directory containing python.exe. Its Scripts subfolder commonly contains pip.exe. Add these as two separate PATH entries. If the Scripts folder does not exist or does not contain pip, the installation may not include pip and may need to be repaired or modified.

Add Python to User Path through Windows settings

  1. Open Windows Settings and search for environment variables.
  2. Choose Edit the system environment variables.
  3. In the System Properties window, select Environment Variables.
  4. Under User variables for your account, select the variable named Path. Choose Edit. If it does not exist, choose New, create Path, and then edit it.
  5. Choose New and add the directory containing python.exe, for example C:\Users\YourName\AppData\Local\Programs\Python\Python312.
  6. Choose New again and add its Scripts directory, for example C:\Users\YourName\AppData\Local\Programs\Python\Python312\Scripts.
  7. Choose OK in the Path editor, then choose OK in each remaining environment-variable dialog.
  8. Close every Command Prompt and PowerShell window. Open a completely new terminal session.

User Path applies only to the signed-in Windows user and is the recommended choice for a normal personal Python setup. System Path applies to all users and commonly requires administrator permissions. Use System Path only when a system-wide configuration is intentional.

Use the Python installer option

The official Python installer includes an option similar to Add Python to PATH on its initial setup screen. Selecting it adds the appropriate Python directories automatically.

If you are uncertain where Python was installed, or if the installation is damaged or missing pip, rerunning the installer may be simpler than manually finding and editing PATH. Depending on the installer, choose the existing installation and select its modify or repair option, or run the installer again and enable the PATH option. A reinstall or repair can also restore missing files, but check which versions and packages you already use before changing an installation.

Verify the updated configuration

Open a new Command Prompt or PowerShell window after saving PATH changes. Existing terminals keep the environment they received when they started.

python --version
pip --version
python -m pip --version
where python
where pip
python -c "print('Python is working')"

The first command should print a Python version. pip --version reports both the pip version and the Python installation associated with it. python -m pip --version checks pip through the interpreter selected by python, which is often more useful when several installations exist.

where python and where pip show which executable locations are being found. When several results appear, the first matching executable generally wins for an unqualified command. Confirm that the first result is the installation you intend to use.

Use pip reliably with multiple Python versions

pip is Python's package installer. A plain pip command can belong to a different Python installation from the one selected by python. This is a common cause of packages appearing to install successfully but not being available to a program.

For the Python selected by the python command, prefer:

python -m pip install package-name

The -m option asks that interpreter to run pip as a module, keeping the interpreter and package installer together.

The Python Launcher is the Windows py command. It can discover installed versions and select one explicitly:

py --list
py -3.12 --version
py -3.12 -m pip install package-name

Replace 3.12 with an installed version. Use py --list to see versions recognized by the launcher. The version-specific pattern is safer than relying on whichever plain pip happens to appear first on PATH.

MethodExampleSelection behaviorBest use case
Unversioned interpreterpythonUses the first matching command on PATH.A single installation or a deliberately configured default.
Launcher defaultpyUses the launcher's default registered version.General Windows version selection.
Launcher with versionpy -3.12Selects the requested major/minor version.Running a precise installed version.
Interpreter-bound pippython -m pipRuns pip belonging to the selected python.Installing packages without mixing installations.
Version-bound pippy -3.12 -m pipRuns pip for the selected launcher version.Installing into a specific Python version.

Understand PATH order and conflicting installations

Windows normally searches PATH from beginning to end and uses the first matching executable. Older Python installations, virtual environments, other language tools, and Store aliases can therefore affect the result.

A virtual environment is an isolated Python environment with its own interpreter and packages. When activated, its directories are intentionally placed before other PATH entries. That is useful inside the project, but it means where python may show the virtual environment first.

To investigate a conflict, run:

where python
where pip
py --list

In the Path editor, move the intended Python entry higher, or remove obsolete entries carefully. Do not remove a virtual-environment entry while that environment is active unless you understand the effect. After changing PATH, open a new terminal and run where python again.

Check Windows execution aliases

If python produces a Microsoft Store prompt even though Python is installed, open Windows Settings and search for App execution aliases. Find the entries for python.exe and python3.exe.

When using a separately installed Python, disable conflicting Python Store aliases if they are enabled. Then confirm that the real interpreter directory is on User Path or System Path, open a new terminal, and test python --version and where python.

An alias problem and a PATH problem are different: an alias can intercept the command before the intended executable is selected, while a PATH problem means the intended executable cannot be found through the configured directories.

Temporary versus persistent PATH changes

A persistent User or System Path change is stored in Windows and is used by new processes. A temporary change affects only the current terminal session and programs started from it.

In Command Prompt, this displays the current session's PATH:

set PATH

In PowerShell, use:

$env:Path

These commands inspect PATH; they are not the primary method for making a permanent configuration. Avoid replacing PATH wholesale. Preserve existing entries and add only the directories you need. System-level changes may require administrator rights, while User Path is normally sufficient for a per-user installation.

Common problems and fixes

SymptomLikely causeHow to confirmResolution
python is not recognized.Python is not installed, its interpreter directory is absent from PATH, or the terminal is old.Find python.exe; inspect where python; open a new terminal.Add the interpreter directory to User Path, then reopen the terminal.
Windows offers the Microsoft Store.A Python App Execution Alias is enabled.Check App Execution Aliases and run where python.Disable conflicting aliases and correct the intended PATH entries.
python works but pip is not recognized.The Scripts directory is missing or pip is not installed.Check for pip.exe; run python -m pip --version.Add Scripts to PATH, use python -m pip, or repair the installation.
Python and pip use different installations.Multiple PATH entries have an unexpected order.Compare where python with where pip.Use python -m pip or py -3.x -m pip; adjust obsolete entries carefully.
PATH edits have no effect.The terminal, IDE, or editor was not restarted, or the wrong folder was added.Open a new terminal and inspect where python and the effective PATH.Restart the program and verify both interpreter and Scripts directories.
A System Path edit cannot be saved.The account lacks administrator permission.Check whether Windows requests elevation.Use User Path, or use an administrator account for a deliberate system-wide setup.

Quick checklist

  1. Locate the directory containing python.exe.
  2. Locate its Scripts subfolder containing pip.exe.
  3. Add both directories as separate entries in the current user's Path.
  4. Preserve all existing PATH entries.
  5. Close and reopen Command Prompt, PowerShell, or your IDE terminal.
  6. Run python --version, python -m pip --version, and where python.
  7. When multiple versions exist, use py --list and version-specific commands such as py -3.12 -m pip.

Once Python is available by name, you can continue with running Python code, learn about the command line, or explore the broader Python online course.