How to run a python script from the command line in Windows 10
In this tutorial, we are going to see how to run a python script from the command line in windows 10. Running a Python program is a very easy task after installation. Here are the steps:
Python program:
print("Welcome To StackHowTo!")
Output:
Welcome To StackHowTo![st_adsense]
How to compile and run the above program
Step 1 : Open a text editor, like Notepad on Windows, and TextEdit on Mac. Copy the above program and paste it into the text editor.
You can also use an IDE like PyCharm to run the python program but to keep things simple, we’ll only be using the text editor and command prompt (or terminal) for this tutorial.
Step 2 : Save the file as test.py.
Step 3 : In this step we will run the above program. To do this, open the command prompt (CMD) in Windows, or Terminal if you are on Mac OS.
To compile the program, type the following command and click on “Enter”.
python test.py
If you get this error, you must first set the path before compiling.
[st_adsense]
Define the path in Windows:
To set the Python environment variable:
1- Go to your computer properties

2- Click on Advanced System Settings

3- Click on Environment Variables

[st_adsense]
Under System Variables, scroll down to find the Path variable then click on “Edit”.

Copy the path to the C:\Python27 folder where the Python executable is located. For python 3 the path to the executable is: C:\Users\(username)\AppData\Local\Programs\Python\Python37

Click on “New”.

Add the value C:\Python27.

Click on the “OK” button of the three windows.
Now you can run your Python script from the command line on Windows 10.
[st_adsense]