How to Configure Python PATH Environment Variables in Windows & Linux

One of the most frequent stumbling blocks for students and new programmers on Windows is the infamous error message: 'python' is not recognized as an internal or external command, operable program or batch file. This error happens when your operating system's PATH environment variable does not know where the python.exe executable lives. In this lesson, you will learn exactly how to locate your Python installation and add it to PATH permanently.

Windows Environment Variables Dialog Window

Figure 4.1: Accessing Windows Advanced System Settings to configure Environment Variables.


What is the PATH Environment Variable?

When you open Command Prompt or PowerShell and type python, Windows does not search every hard drive on your computer. Instead, it looks only inside the specific directory folders registered in a special system registry list called PATH. If Python's installation directory is registered in PATH, Windows launches Python immediately regardless of which folder your terminal is currently navigating.


Step-by-Step: Adding Python to PATH in Windows 11 & 10

Follow these 5 visual steps to add Python to your PATH permanently:

• Step 1: Locate Your Python Install Path: Typically, Python installs under your user profile directory:

# Typical Windows Python 3.12 location:
C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python312\
C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python312\Scripts\

• Step 2: Open Environment Variables: Press Windows Key + S, type "env", and click "Edit the system environment variables".

• Step 3: Click Environment Variables Button: In the System Properties window that appears, click the button labeled "Environment Variables..." near the bottom right.

Select Path variable in User Variables window

Figure 4.2: Selecting the Path entry under User variables and clicking Edit.

• Step 4: Edit the PATH Variable: Under User variables for <YourUsername> (or System variables), locate and select the line named Path, then click Edit....

• Step 5: Add the Two Entries: Click "New" on the right, and paste your Python folder path. Click "New" again and paste the Scripts\ path. Click OK on all three open windows to save!

Adding Python and Scripts directory to Path list

Figure 4.3: Adding both the base Python directory and the Scripts directory to the PATH list.


Configuring PATH in Linux & macOS (Bash / Zsh)

On Unix-based operating systems (Linux Ubuntu, Debian, macOS), environment paths are managed inside your shell startup profile (~/.bashrc or ~/.zshrc):

# Check current PATH in Linux / macOS terminal:
echo $PATH

# Add custom Python path permanently to ~/.bashrc:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Testing and Verifying PATH Configuration

Important: After editing environment variables on Windows, you must close and reopen your Command Prompt or PowerShell window so that it reloads the new PATH settings. Then run:

# Check where python executable resides:
where python

# On Linux or Mac:
which python3

Expected Output:

C:\Users\sp\AppData\Local\Programs\Python\Python312\python.exe
C:\Users\sp\AppData\Local\Programs\Python\Python312\Scripts\pip.exe

Frequently Asked Questions (FAQ)

Why must the Scripts/ folder also be added to PATH?

The Scripts/ subfolder contains executable tools installed via Python, most importantly pip.exe (Python Package Installer) and CLI tools like pytest, black, or virtualenv. Adding Scripts ensures these tools can be run directly from any terminal.

Can I have multiple versions of Python in my PATH?

Yes. On Windows, you can use the built-in Python Launcher (py). Typing py -3.11 or py -3.12 will run the exact version requested without conflicts.
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!