
Add *.py file extension at the end of the name of the script.Always enclose the name of the script inside a pair of double quotes and.Like this: D:\Python Tutorials>python "tut1.py" In order to execute a script we need to accompany the keyword “python” with the name of the script enclosed inside a pair of double quotes. Python’s interpreter can be invoked simply by writing keyword “python” on command prompt. Step 2: Invoke the Python interpreter to run the script. For example to get into the directory “Python Tutorial” simply write “cd Python Tutorials” To change the current directory in command prompt we use “cd” command.For example to change from C to D drive simply write D: and hit enter. To change the drive in command prompt simply write the drive letter along with colon and hit enter.For example in my case the script is located at “D:/Python Tutorials/Tut1.py” so I need to navigate my command prompt to this location. In order to execute your script using command prompt you first need to locate the script in window’s file system and then navigate your command prompt to its location. Navigating To the Directory Step 1: Navigating to the script location. Let’s start with the first way which is navigating to the directory. Let’s try to execute our script “Tut1.py” using both the above mentioned ways. The interpreter will use the location path to find the script and then execute it. Invoke the Python interpreter with the location of your script.In your command prompt, navigate to the directory where your scripts are saved and then execute them using Python interpreter.
#Run a python script from terminal how to#
Now let’s move ahead and learn how to execute this script using command prompt in windows 10.
