Programming has become the most prominent technological course to be learned. Apart from good logical thinking skills, you need successfully installed software to excel in this field. Python is the most fundamental programming language to learn, but you may experience some errors while installing the Python setup. For Windows users, the most common error displayed on your computer screen can be “Python is not recognized as an internal or external command.”
This article will guide you through the causes of this error and how you can fix it.
Steps To Access Python On Your Computer
The first method to access Python on your computer is to follow the path of the installed software and access the executable file directly.
The screenshot shows how you can locate the downloaded executable file and open Python.
Performing this task opens the IDE of Python, where you can code hassle-free.
The second method to access Python is through the command prompt. The steps of this method are as follows:
1) Open the command prompt through the search tab of Windows.
2)Type Python and press enter
Following this step, the Python IDE opens in the same window. But in some cases, an error might occur as follows.
Cause Of Error
Whenever we access any file or an installed program, our computer needs to know the entire location of the place where the file is stored. The computer reads this location as the ‘path’ of the file. When we accessed the Python executable file by going directly to its location, we followed the file's path, which eliminated the possibility of error. But, when we use the command prompt to access the file, the path may or may not be known to the computer. If the path is not known to the computer, Windows will not run the program and display an error message.
The Path Variable
The computer knows the path of a file through the path environment variable. You can think of a path environment variable as a set of directories containing the address of executable files of installed programs. The path variable makes it easier for the computer to search for programs. However, if this path variable is loaded with many unnecessary paths, it will slow down the computer. Thus make sure that you mention the paths correctly and selectively.
When we type a program name in the command prompt and do not specify the directory(or, more specifically, the path), the computer system searches all the paths mentioned in the path environment variable. Suppose the path(of that specific program) is mentioned in the environment variable. In that case, the computer system will be able to locate the executable file and run it. However, suppose the computer system does not find any path leading it to the executable file. In that case, it will display the error message.
Therefore we need to ensure that we add the path of the Python executable file in the path environment variable.
Fixing The Error
Solution 1
The first approach towards fixing this error can be mentioning the path of the executable file in the command prompt itself so that the system doesn't have to search in the path environment variable.
We can find the path of executable variable as follows:
Step 1: Open the search tab of Windows and type Python.
Step 2: Click on ‘Open File Location’
Step 3: The PC Explorer window opens.
Step 4: Right-click on the ‘Python 3.9(64-bit)’ and select 'Open File Location.'
Step 5: Look for the file 'python.exe.' Right-click on this file and then select 'Properties.'
Step 6: You can see ‘Location’ and the entire path of the python executable file.
Step 7: Copy the path and paste it in the command prompt.
Step 8: Add a backslash ‘\’ and write ‘python.exe’ and press enter.
Now you can run Python successfully in the command prompt.
In this method, you will have to copy the path in the command prompt every time you open Python. This process can be tedious and time-taking. To save you from all this trouble, let's see what the second approach has to offer.
Solution 2
The concept of this approach is to add the path of the python executable file to the Path environment variable so that the computer can search through the directories itself. There are two different ways in which you can add the path to the environment variable:
Using The Python Set-Up To Update Path Variable
When you install Python, the setup initially offers you the option to add the path of the executable file to the path environment variable. You can check the box, and the path will get automatically added.
Suppose you missed checking this option when you first installed Python; no need to worry! You can still modify the installation setup and update the path variable by following these steps:
Step 1: In your File Explorer, search for ‘python-3.9.6-amd64’ and open it.
The installer will now look like this:
Step 2: Click on Modify. The window will now appear like this:
Step 3: Click ‘Next’ till you get the ‘Advanced Options’ window.
Step 4: Check the option titled “Add Python to environment variables” and then click install.
Now the path variable of your system has been updated, and you can access Python through command prompt without any errors.
Updating The Path Variable Manually
The most critical requirement for updating the path variable manually is that you should have the python executable file's location(or, more appropriately, path). You can follow the steps given in ‘Solution 1’ to obtain the required path.
After obtaining the path, you can follow the following steps :
Step 1: Open ‘Settings’ on your computer.
Step 2: Click on 'System' in the settings window and then click 'About' from the options available on the left-hand side.
Step 3: Click on 'Advanced System Settings ' on the right-hand side of the about window.
Step 4: Click on ‘Environment Variables’ on the bottom-right corner of the window.
Step 5: In the Environment Variable window, click on the Path option( it will make the text background blue) and then click on 'Edit.'
Step 6: In the Edit Environment Variable Window, click on 'New'(right-hand side of the window).
Step 7: Upon clicking 'New,' the cursor will start blinking, and you can paste the Python executable file path here.
Step 8: Click 'OK,' and your job is done!
After completing all these steps, you will be able to run Python through the command prompt, error-free.
Conclusion
A programmer should understand several different aspects of an operating system to deal with errors while installing or coding. "Python is not recognized as an internal or external command" is a very basic problem that a programmer may encounter initially. We hope that this article helped you in fixing this error. You can apply any solution method and correct your system to code efficiently. Now that you have installed Python and can run it error-free, you can conquer the logical world with your unique codes. Happy coding!