The “python is not recognized as an internal or external command, operable program or batch file” error is encountered in the Windows Command Prompt when Python’s executable file is not found in the environment variable in the Windows Command Prompt.
Each program on your computer has an executable file associated with it. The executable file contains all the information needed by the computer to execute that program.
The location of the executable file for a specific application can be found in its operating system specifications or system path.
This article walks you through the process of solving this error.
What are Environment Variables?
The environment variable is the set of variables or parameters which are used in an operating system for running a program. The environment variables can change the way your program runs by defining the location of executable files, data files, and configuration files.
Environment variables are user-configurable and enable developers to customize an installation’s directory structure, temporary file locations, and user settings location.
Solution 1: Update the Environment Variables
- Find the folder to the installed Python version on your computer. This is usually C:\Program Files\Python27 or some variation. If this folder does not exist, download it here.
- After you find it, copy the path of this Python folder.
- Click on the Start Menu and right-click on My Computer. Select Properties > Advanced System Settings > Environment Variables.
- When the Advanced window appears, click on Advanced Variables.
- When the Environment Variables window appears, find the PATH variable and click Edit.
- Add the Python path (e.g., ;C:\Program Files\Python27) to the end of the string and click OK.
Solution 2: Use “py”
In the Windows Command Prompt, type “py” instead “python”. The command “python” should be registered automatically but your computer may be registered “py” only.
C:\Users\samb> py -V Python 3.7.1
You should see the output of the Python version.
Solution 3: Re-Run the Python Installation
In this solution, you would re-run the Python installer again. When prompted with the “Advanced Options”, make sure the “Add Python to environment variables” is checked.
Solution 4: Update From the Command Line
Open the Windows Command Prompt with Administrative Access. This can be done by right-clicking on the Windows Command Prompt.
At the prompt, set the environment variable to the following:
set PYTHONPATH=%PYTHONPATH%;C:\Program Files\Python27
This assumes Python is installed in C:\Program Files\Python27. If this is not the case, change it to the path for your use case.
If you have been a Python user for a while, this error should sound familiar. This error is not unique to Python and can be thrown by other applications as well. The most common cause of this error is that your environment variables were not set correctly.
The next time this happens, just reset the variable with one of the solutions listed above.