Online Tutorials & Training Materials | STechies.com
Register Login

Python is not recognized as an internal or external command, operable program or batch file

|| 0

Python is not recognized as an internal or external command, operable program or batch file
Stechies

After installing Python on our PC when we try to run the console command python.exe, we sometimes get the following error message:

'python' is not recognized as an internal or external command, operable program or batch file

This error occurs when the user does not specify the full path of python distribution. Therefore we can resolve this error by:

1) Adding a Python to the PATH Environmental Variable in Windows 

2) Adding Python to Environmental Variable in Python Installer

But before that, we need to know what is Environment variables in Windows and its role.

What is Environment variables?

Environment variables are variables that create the environment in which programs runs in your computer. It enables user to specify the directory to install files in, location to store temporary files, and also the location to find user profile settings. In the same way, python environment variable help system to specify the location of the python executable.

Option 1) Adding a Python to the PATH Environmental Variable in Windows 

Here is step by step process of adding a full path of python distribution in Environmental Variable:

1.Open Computer/System Properties

Press (Windows Key) and Type "This PC" then right-click on Computer (This PC) and select Properties.

2. Inside 'Property' window click on 'Advanced system settings'

3. Now click Environment Variables button at the bottom (here we will add the full path of python distribution).

4. In the 'Environment Variables' window select 'Path' variable and click 'Edit'.

5.  Now click on the 'New' button to add Python Environment Variable. 

For Example: "C:\WINDOWS\system32;C:\WINDOWS;C:\Python32”

Edit Environment Variable

Note: C:\Python32: is your python installation directory. 

In the latest version of Python the setup get installed in

"C:\Users\Shalesh\AppData\Local\Programs\Python\Python37-32\Scripts\"

6. Click 'OK' to save the changes and then run Python command from the command prompt.

Note: The procedure explained above works fine with Windows 7, Windows 8 (8.1) and Windows 10

Option 2) Adding Python to Environmental Variable in Python Installer

1.Download the same version of Python executable installer from Python.org (https://www.python.org/downloads/release/python-374/)

Note: In this tutorial, we are using Python 3.7

2. Run python Setup and select the 'Modify' button

3.In the next window click 'Next' 

4. In 'Advanced Options' window check 'Add Python to environment variables' and click on 'Install'.

Note: You don't need to uninstall the older version of python, just modify the previous installation. 

Now if you run python through command prompt it will give you the following result:

C:Usersmypc>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

This implies that all is OK and your system is ready to run python