- An Overview:
- Introduction to Environment Variables
- Final Words
One of the most infuriating things about studying Python is that it needs no coding. Simply getting Python executed on a personal computer can be a major hurdle for several beginners.
While trying to launch Python through the Command Prompt, Windows users could receive the following strange and complicated error message: ‘python’ is not recognized as an internal or external command, operable program, or batch file.
What is the Python Error?
The error message “Python is not recognized as an internal or external command” is seen on the Windows command prompt. When the Python executable file is unable to detect an environment variable due to the Python command in the Windows command prompt, the error occurs. Since the problem occurs during execution, even if users simply entered Python code into the console, they can deduce that it is not a coding issue but rather a setup issue, and they would be correct.
To run some tasks, the Windows command prompt uses information from the computer’s libraries and packages. Windows evaluates environmental variables on the machine to determine where the file that will execute Python is located. The Python code is not recognized as an internal or external command, operable program, or batch file message is presented if it is not found.
Reasons for the “Python Is Not Recognized As An Internal Or External Command, operable program or batch file” error:
When trying to run Python on a Windows system, developers may get this problem. This could be due to an outdated Windows version or the deletion of specific settings. The main cause of the error is that the whole path to the appropriate Python distribution must be saved in the computer’s Environmental Variables list.
The PATH environment variable can be readily added to fix this problem.
- Adding Python to the PATH Environmental Variable in Windows
- Adding Python to Windows Environmental Variable using Python Installer.
Introduction to Environment Variables
Environment variables are variables that define the conditions under which computer programs run. It allows the user to define the directory in which files should be installed, where temporary files should be stored, and where user profile settings should be found. Similarly, the python environment variable assists the system in determining the location of the Python executable.
Adding a Python to the PATH Environmental Variable in Windows
Here’s how to add a whole path of Python distribution to an Environmental Variable step by step:
- Open System or Computer Properties.
- Type “This PC” into the Windows Key, then right-click on “This PC” and select Properties.
- Select the ‘Advanced system settings’ option in the ‘Property’ window.
- The entire path of the Python distribution will be added if you click the Environment Variables button below.
- Select the ‘Path’ variable in the ‘Environment Variables’ window and the ‘Edit’ option.
- Add Python Environment Variable to the ‘New’ button now.
- The setup is installed in the path added in the most recent version of Python.
- To save your modifications, select ‘OK,’ and then run the Python program from the command prompt.
Adding the Python to Windows Environmental Variable using Python Installer
Python.org provides the same Python executable installer version
- Run python Setup and select the ‘Modify’ option
- Select ‘Next’ in the next window
- Check ‘Add Python to environment variables’ and click ‘Install’ in the ‘Advanced Options’ menu.
- Users can now run python from the command prompt and get the following output.
This is evidence that everything is in working order and that the system is ready to execute Python.
What are the Alternative Options that could be experimented with?
Instead of typing “python,” users can enter “py.” Users should now be able to use Python without receiving an error notice. Follow the procedures above if users want to use the entire word in the code — “python.”
If customers download a recent version of Python, there may already be an option that adds Python to the system path for them, so they don’t have to. Check the box next to “Add to Environmental Variables.”
About the Installer
When users download Python from the official Python downloads page, the computer saves an installation file named python-3.9.5-amd64.exe or something similar to a specified directory, generally the Downloads folder. Users can upgrade their Python installation and add its path to the system PATH using the same installer.
From the Start menu, look for the installer, or look for it in the Downloads folder, or wherever users saved it. Instead of asking customers to install Python this time, it should give them a number of options for changing the setup.
Users will be taken to the Optional Features page after clicking Modify. Users should click Next until they reach the Advanced Options page. Select the Add Python to environment variables checkbox on this page.
The Python installation will be modified, and the executable application location will be added to the system PATH variable. Users can enter the interpreter by typing python on the Command Prompt once the modification is complete. At this time, users should experience no problems.
About Manual Procedure
Users can always alter the PATH environment variable themselves if they can’t find where they got the Python installer or if it has already been uninstalled from the computer. This section will lead users through the process. The entire path to the directory containing the python.exe program file is required first.
Users must append the file location to the end of the system PATH once they obtain it. To change the path, go to the system settings first. Users may normally access system settings by going to the Start menu and looking for ‘About your PC.’ In the menu on the right-hand side, select Advanced system settings.
Users will be taken to a dialogue box called System Properties. Select Environment Variables from the Advanced menu. The Environment Variables dialogue box will appear. The PATH of the system is defined here. Users will want to update this variable to instruct the Windows PC where to look for the Python executable program. Make sure the path environment variable is checked and selected, then click Edit.
Users will now be allowed to change the PATH environment variable. By selecting New, a new element should be added to the list. Users should type the complete path to the directory containing the python.exe file they found before in this box. Click OK on each dialogue box until the users have completely departed them. That’s everything! Users should be able to type python into a Program Prompt and have the command run without issues.
In conclusion, if you see this error message even though you know you installed Python, it’s highly likely an issue with environment variables. Simply repeat the steps outlined above. If you find it too difficult, simply reinstall Python and ensure that the “Add to Environmental Variables” option is selected. Bugs and system inconsistencies are frequently resolved by updating both your operating system and the application/program you’re trying to utilize.