Python is one of the most used programming languages today, and given its popularity, it’s no wonder you are eager to start coding with it.
If you just installed Python on Windows, you may run into an issue in the command prompt that doesn’t allow you to execute any code. Since the problem is at execution, even if you just typed a Python code into the console, you can guess that it’s not a coding problem and rather a setup problem — and you’d be right.
The Windows command prompt relies on information in the computer’s libraries and packages to run some commands. For executing Python, Windows checks environmental variables on the computer to know where to find the file that will execute Python. If it doesn’t find it, then the Python code is not recognized as an internal or external command, operable program or batch file message is displayed.
It is not common for users programming on computers such as a Mac to see this error, since Python comes pre-installed on macOS. If you have a Mac and want to uninstall a Python version you downloaded, follow these steps.
What is causing the ‘Python’ is not recognized as an internal or external command, operable program or batch file” error?
Developers using a Windows machine may find this error when they try to run Python. This could be due to the Windows version being outdated, or if some settings were deleted. The underlying reason for the error that the full path to the correct Python distribution has to be saved in your computer’s Environmental Variables list.
This error can be easily addressed by adding your PATH environment variable.
Adding Python to the Windows PATH Environment Variable
Doing this can prove confusing if it’s your first time. So, we’ll go over the process of choosing the correct path to copy in Step 1. Then, we’ll move on to copying that path in the appropriate spot in your system’s environment variables in Step 2.
Step 1: Look in your programs for the Python folder where the version you installed is and copy the file location path.
1. Search your system for “python”. Right-click on the one that has Python, the version number, then (64-bit) and choose “Open file location”.
2. The file manager application should open along with the search results for python. If the Type column for python says ‘Shortcut’, then right-click again and choose “Open file location”.
3. You should see “Application” under “Type”:
4. Right-click again and choose “Properties”. Copy the “Location” path.
Step 2: Add to the PATH Environment Variables
1. From the system search icon, type “environment variables”. Click and open the result.
2. You’ll see your variables here. Select the PATH variable and click the “Edit” button.
3. In the following window, click “New” and paste the path you copied in Step 1.
4. Click “OK” to save.
If you have an older Windows version (such as Windows 7):
- From the Start Menu, right-click My Computer (could also be My PC or File Explorer).
- Select Advanced System Settings.
- In the Advanced Tab, Click on the Environmental Variables button.
- Find “Path” in the System Variables list and select “New”.
- Finally, paste the path you copied earlier in Step 1. If your system has lots of paths linked by semicolons, append the path by prefacing it with a semi-colon also.
- Click “OK” to save.
Try running Python again at the command prompt. Remember you may have to close and reopen the command prompt for the changes to work.
Alternative Options
You could also try type in “py” instead of “python”. This should let you use Python without returning the error message. But if you want to be able to use the full word in your code — “python” — then follow the steps above.
If you are downloading a recent version of Python, there may already be an option that will automatically add Python to the system path so that you don’t have to. Look for “Add to Environmental Variables” and check it.
Conclusion
In summary, if this error message appears even if you know you installed python, it’s very likely it’s an environment variable issue. Just follow the steps above and try again. If you find it too complicated, you can also just reinstall Python and carefully check that you opt for the “Add to Environmental Variables” option.
Bugs and system discrepancies can often be fixed by installing the latest version of both your operating system and the application/program you’re trying to use. Not everyone has that option, however. For example you may be using a work laptop on which you don’t have certain needed permissions, or an older one you don’t want to part with. Read more about using Python on Windows here. Good Luck!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.