Skip to main content

How to Resolve "'python' is not recognized as an internal or external command" Error in Windows

When you try to run Python from the Windows Command Prompt or PowerShell, you might be met with the error: 'python' is not recognized as an internal or external command, operable program or batch file. This is a very common issue for beginners and simply means that the Windows operating system does not know where to find the Python executable (python.exe).

This happens when the directory containing python.exe is not listed in your system's PATH environment variable. This guide will walk you through the two primary solutions: the easy fix during installation and the manual method for adding Python to the PATH afterward.

Understanding the PATH Environment Variable

The PATH is a system variable on Windows that contains a list of directories. When you type a command into the terminal (like python), Windows searches through each directory in this list to find a matching executable file. If it can't find python.exe in any of the listed directories, it gives up and shows the "'python' is not recognized" error.

The solution is to ensure the folder containing your python.exe file is included in this PATH list.

Reproducing the Error

Example of command causing the error:

C:\Users\YourUser> python --version

'python' is not recognized as an internal or external command,
operable program or batch file.

Solution 1: Reinstall Python with the "Add to PATH" Option (Easiest Fix)

If you are just starting out or don't mind reinstalling, this is by far the simplest and most reliable solution.

Solution:

  1. Uninstall Python: Go to "Add or remove programs" in Windows Settings, find your current Python installation, and uninstall it.
  2. Download the Installer: Get the latest official Python installer from python.org.
  3. Run the Installer and Enable the PATH Option:
    • Launch the installer.
    • On the very first screen, make sure to check the box at the bottom that says "Add python.exe to PATH".
warning

This is the most critical step. Forgetting to check this box is the reason the error occurs in the first place.

  1. Complete the Installation: Proceed with the standard installation.
  2. Restart Your Terminal: Close any open Command Prompt or PowerShell windows and open a new one for the changes to take effect.

Solution 2: Manually Add Python to the System PATH

If you prefer not to reinstall Python, you can fix the issue by manually editing the PATH environment variable.

Step 1: Find Your Python Installation Path

First, you need to know where Python is installed. The Python Launcher (py.exe), which is usually installed by default, can help you find this.

Find the Path:

C:\Users\YourUser> py -c "import sys; print(sys.executable)"

C:\Users\YourUser\AppData\Local\Programs\Python\Python311\python.exe

From this output, we can identify two important paths we need to add:

  1. The directory containing python.exe: C:\Users\YourUser\AppData\Local\Programs\Python\Python311\
  2. The Scripts directory (for pip): C:\Users\YourUser\AppData\Local\Programs\Python\Python311\Scripts\

Step 2: Add the Path to Your Environment Variables

You can do this through the Windows GUI, which is safe and user-friendly.

Solution (GUI Method):

  1. Press the Windows key, type "Edit the system environment variables", and press Enter.
  2. In the System Properties window that opens, click the "Environment Variables..." button.
  3. In the "System variables" section at the bottom, find and select the variable named Path, then click "Edit...".
  4. In the "Edit environment variable" window, click "New".
  5. Paste the first path you found (e.g., C:\Users\YourUser\AppData\Local\Programs\Python\Python311\).
  6. Click "New" again and paste the Scripts path (e.g., C:\Users\YourUser\AppData\Local\Programs\Python\Python311\Scripts\).
  7. Click "OK" on all open windows to save the changes.
  8. Restart your terminal for the new PATH to be loaded.

Verifying the Fix

After following either solution, open a new Command Prompt or PowerShell window and test the python command again.

Verification:

C:\Users\YourUser> python --version

Python 3.11.4

If you see the Python version number, the PATH is configured correctly and the error is resolved.

Conclusion

If you are...The best solution is...
Installing Python for the first time or don't mind reinstalling.Reinstall and make sure to check the "Add python.exe to PATH" option.
Looking to fix an existing installation without reinstalling.Manually find the python.exe and Scripts directories and add them to your system's PATH environment variable.

The python is not recognized error is a simple configuration issue that can be quickly fixed by ensuring the Windows PATH variable includes the location of your Python installation.