Python is not recognized as an internal or external command, operable program, or batch file (Fixed)

You installed Python and are ready to begin learning and developing with Python. Instead, you find yourself immediately stalled by an unknown error. The ‘python is not recognized as an internal or external command, operable program or batch file’ error is prevalent among Windows users trying to access Python from the Command Prompt. You know you installed Python, so what’s the problem? 

Don’t be alarmed. This error is extremely common among Python beginners. This troubleshooting guide will provide solutions to fix the error and useful background information on environment variables and PATH.

Python is not recognized as an internal or external command, operable program, or batch file error message in Command Prompt

Python for beginners

Python is a popular high-level object-oriented programming language that was developed in 1991. The Python programming language is an especially popular choice among novice programmers because its syntax is similar to English and easy to learn. Python can be used for a wide range of applications, so learning this language can prove highly valuable. Data science, web development, machine learning, and automation are popular uses of Python. 

There is a huge range of free or low-cost education resources on the internet for those wanting to learn Python. Python itself is open-source and can be installed for free on any computer. Learning Python can seem daunting at first, but selecting a niche of interest within Python can be really helpful.

What do you want to use Python for? Do you want to automate all your daily tasks? Do you want to build a web application? Do you want to develop a machine learning algorithm? Look into each of these areas and see what interests you most. Then select tutorials and resources that lead you through those activities. 

Before you can get started learning to code, you need to get Python to run on your local environment. Read more to learn how to solve the most common error encountered by new Python users.

What causes the ‘python is not recognized as an internal or external command, operable program or batch file’ error?

If you’ve been running Python in an IDE up until this point, you wouldn’t have seen this error. By navigating to the location of the Python executable file and clicking on it to open it, you let the operating system know the exact location of the file. But once you switch over to Command Prompt and call for Python, your system does not automatically know where this file is located. 

You need to explicitly tell your machine where the Python executable can be found. This is done by adding the location of the Python executable to your PATH environmental variable. 

PATH? Environmental variable? 

Those are terms you may not be familiar with if you are new to programming. Let’s break down what each term means and how it relates to solving this ‘python is not recognized as an internal or external command, operable program or match file’ error.

What is an Environment Variable? What is PATH?

Environment variables provide your system with important runtime environment information. They tell the computer facts about the runtime environment of the current operating system. Environmental variables that are found on systems running a Windows operating system include:

  • %systemroot% – path to computer’s root, usually C:\Windows
  • %homepath% – path to the primary user’s home directory, \User\{username}
  • %path% – list of paths Windows will search for executables when a command is run, C:\Windows\system32
  • %windir% – location of Windows installation directory, C:\Windows

As you can see, PATH is an environment variable that directs your computer where to find executable files. When you open the Command Prompt and attempt to run Python, Windows will search through the directories your system has listed in the PATH. It’s searching for the location of the executable you are calling so that it can execute it. 

If you have installed Python in a directory or location that is not listed in the PATH environmental variable – and you have if you are receiving this error – then when Windows searches PATH, it won’t find any Python executable. As a result, you see an error.

Environmental Variables and Python Packages & Modules 

The information contained in this section isn’t directly related to solving the ‘python is not recognized as an internal or external command, operable program or batch file’ but will be extremely valuable when installing python packages and modules.

You learned how adding the path of the Python executable to PATH allows for ease of use in Command Prompt. Well, the same applies to packages and modules. You can use Environment variables to configure your Python application. By adding directories to Python’s environment variables, you can point Python to look for packages and modules in other locations. 

Packages and modules are incredibly useful when building Python applications. You should only code what you have to code. Other programmers have developed packages and modules to perform certain functions. By installing and using these, you can drastically shorten your development time and be far more efficient.

Packages and modules are not required components to run Python. When you create a Python application, it will not automatically be set up in the standard library. But if you add the directories that contain your packages and modules to PYTHONPATH, then custom Python libraries will be accessible to every Python program you made. 

Check out this resource to learn how to add directories to PYTHONPATH.

Adding Python To PATH During Installation

The Python installer allows the user to add the Python executable location to PATH during installation. Unfortunately, this is optional, and there is no obvious information provided for new users about the importance of selecting this step. That’s why so many Python beginners miss this selection and experience the ‘python is not recognized as an internal or external command, operable program or batch file’ error. This option also adds your Scripts\ folder allowing you to easily execute your scripts in the Command Prompt. 

Add Python to PATH during installation to fix the "Python is not recognized as an internal or external command" error

You can re-run the installer and select Modify and then enable this selection. 

Finding Python’s path

So Windows doesn’t know where the Python executable is located, but do you? If you don’t know the file location for Python, the instructions below will help you find it. You can avoid the ‘python is not recognized as an internal or external command, operable program or batch file’ error by entering the full path to the Python executable into the Command Prompt. 

It would look something like this:

Full Python path in CMD

This method works, but it’s not the most time-efficient. And when you find yourself calling Python again and again, you will probably get tired of typing the full path. 

If you don’t know the full path location of the Python executable on your machine, you will need to locate that to add to your PATH environmental variable. 

To find the full path of Python in Windows 10 or Windows 11:

  1. Click on the Start menu button. Enter “Python” into the search bar. If you have Python installed, it will pull up the latest version of Python.
Search for Python
  1. On the right-hand side, select Open file location from the list. This will open File Explorer. Notice that the file type of Python is a Shortcut. If you see this, right-click on the Python executable shortcut and again select Open file location.
Python shortcut
Open file location
  1. You have now navigated to the folder containing the Python executable. Find the Python executable file with file type Application. Right-click and select Copy as path.
Copy as path
  1. Save this path location in a document, so you can easily refer back to it later on during the solutions portion of this guide.

How to fix the ‘python is not recognized as an internal or external command’ error

Add Python to PATH from system environment variables on Windows 10 or Windows 11

To resolve this error, you can easily add the Python executable path to your system’s PATH environment variable by following the steps below:

  1. Click the Start menu button and enter “environment variables into the search bar. Select Edit the system environment variables.
Edit the system environment variables
  1. In the newly opened System Properties window, click on the Advanced tab and select Environment Variables… at the bottom of the window.
Open environment variables
  1. You can opt to add the Python executable path to User variables if you are the only user of your computer. But this example will show the path being added to System variables. Click Edit…
System variables
  1. Now click New… and paste the location of the Python executable that you saved into this field. Click OK. Then click OK and OK again to close out all windows.
Add new path to resolve the "Python is not recognized as an internal or external command" error
  1. Open Command Prompt and type “python”. Windows will open Python without any error.

Solved: ‘Python is not recognized as an internal or external command, operable program or batch file’ error is fixed

If you walked through this troubleshooting guide, you gained a great deal of knowledge about environment variables, PATH, and how to run Python in the Command Prompt properly.

Python is attractive to new programmers because of the simple syntax and array of uses. When you install Python, you can – and should – select to add Python to PATH, but this option is often overlooked. The Python installer does not do a good job of explaining the importance of this option if you intend to run Python from the Command Prompt. Thankfully, you can very easily rectify this by adding the location of the Python executable to your PATH in system environment variables.

Now that you are up and running with Python, don’t forget to check out our other troubleshooting guides if you run into Python errors during a coding session.

Leave a Comment