In your Window's Command Prompt if you are getting the error ”
'python' is not recognized as an internal or external command, operable program or batch file
” after executing python command. This means either Python is not installed in your system or the PATH variable is not defined for Python for your windows system. If Python is not installed in your Windows system then you can simply visit the official site of Python, and
installed the latest version of Python for your window’s
. Or even after installing the Python, you are getting this error you just need to specify the PATH variable for the installed Python. Before moving to the steps you need to follow on How to set the PATH variable for Python in windows, let’s discuss what is a PATH Variable in the window?
What is the PATH variable in Window?
A PATH variable contains a list of directories(folders), and each directory in the PATH variable contains an executable file for a command. And when we use that command in the Command Prompt the corresponding file executed. For instance, we set a PATH variable for the python executable file we downloaded, and using the python or py command we can execute that file from our command prompt, without going to that specific directory, where the py.exe file is located.
How to add Python to the Windows PATH Variable?
In the latest series of Python3.x.y we do not need to manually set the PATH variable for our installed py.exe file, during the process of installing PYTHON we get an option to set the PATH variable automatically for the python command. However, we can also manually set the variable path for our Python. Here in this article, I have mentioned two ways on how can you add a PATH variable for Python in your window system.
- Automatically set Python PATH variable with the latest version of the installation
- Manually set the PATH variable via environment variables after installation.
Automatically set Python PATH variable with the latest version of Python installation
The easiest way to set the PATH variable for your python is via downloading the latest version of Python and checking the box Add Python to PATH , during installation steps. Steps:
- Go to the official web site of Python and download the latest version
- Click on the download file to install Python in your system.
- Check the “ADD Python3.x to PATH” box and click on the Install Now
This will set the PATH variable for your PYTHON and now you can execute your python command on your command prompt terminal. If you manually want to set the PATH variable for your Python then you can leave the ADD Python to PATH box to uncheck.
Manually set the PATH variable via environment variables after installation.
You can also manually set the PATH variable for your python command using the Window environment variable. To set the PATH manually, Python needs to be installed in your system. Follow the steps given below to set the PATH variable for Python in window 10 STEP 1: Navigate to the Windows Enviable Right-click on the This PC and select the Properties option Now click on the “ Advance System Settings ”
Now click on the “ Environment Variables.. ” button
STEP2: Create a New Path Variable Now click on the New button of the [ User Variable from]
Now you need to fill the two inputs Variable name And Variable Value
In Variable name, you need to type Path. And in Variable value, you need to specify two directories locations separated by a semicolon (;), now find the Python folder in your system. <Note>: The AppData folder may be hidden in your system make sure that Hidden Items are checked in the view
C:\Users\tsmehra\AppData\Local\Programs\Python\Python38-32\Scripts Variable name: Path Variable Value: C:\Users\tsmehra\AppData\Local\Programs\Python\Python38-32 ; C:\Users\tsmehra\AppData\Local\Programs\Python\Python38-32\Scripts
Now hit the OK button and save all changes. Verify if the PATH variable is Set To check if the PATH variable is set for the Python command, you can navigate to the Command Prompt and write the command python or py.
You can also check if the pip command is also working, by typing pip in the command prompt.
If pip is not working then click here to know how to install pip in your system .
Here in this tutorial, you learned how to set the PATH variable in windows for Python. The easiest way to set the PATH variable during Python installation, just make sure to check the Add Python to Path and you are good to go. However, you can also set the PATH variable manually through the Environment variable. The PATH variable allows us to have a specific command to execute a file from any location on the command prompt. People are also reading: