Fix “Python not Recognized” Error in Windows Command Prompt

by Mayank
python-not-recognized

Python is not recognized as an internal or external command, operable program or batch file is a common issue beginners face when they write a python program for the first time and try to run the python shell from the command prompt to execute their code. When you encounter this error, you may naturally deduce that something might be wrong with the program you’ve written. But then you take a look at your code and everything looks perfect. What’s wrong, then?

Diagnosing the error

This problem shows up because Windows is unable to recognize what the word “python” means. Even if you have Python installed on your computer, Windows must recognize where Python is installed so that the Python shell can be launched. In other words, you don’t have a path environment variable set for the Python directory that contains python executable files on your computer.

Learn more about Environment Variables on Windows.

How to Fix the Error

  • Fixing the “python not recognized” error is easy. You just need to create a new path variable for the Python directory on your PC.
  • First, find the directory where Python is currently installed. Most of the time, it’s on the same drive where you have Windows installed on your computer. Here’s the location of the Python directory on my PC.
The directory where Python is installed

Note: If you can’t see the AppData folder inside your User Directory, it’s probably because it’s hidden. To access the AppData folder, go to the View tab on the top bar and check the box next to Hidden Items.

  • Right click on the top navigation pane and select Copy address as text.
Copy the location of the Python folder
  • Open the command prompt.
The Windows command prompt
  • Type the following command and press Enter:

setx Path “Location of the Python directory”

  • That’s it! Now that you have set the path variable, Windows can find Python files on your PC, and you can now easily run the python shell in CMD.
Now when you execute the python command, you should get the shell

Note: If you are still getting the error, launch the command prompt in administrator mode and then try launching the python shell.

We love to hear from you

Did the fix work for you? Got some questions? Feel free to comment below. Also, feel free to suggest more topics for future blog posts.

Related Posts

Leave a Comment