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.
Figure 4.1: Accessing Windows Advanced System Settings to configure Environment Variables.
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.
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.
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!
Figure 4.3: Adding both the base Python directory and the Scripts directory to the PATH list.
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
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
C:\Users\sp\AppData\Local\Programs\Python\Python312\python.exe
C:\Users\sp\AppData\Local\Programs\Python\Python312\Scripts\pip.exe
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.
py). Typing py -3.11 or py -3.12 will run the exact version requested without conflicts.