Run python script from command line
Run python script from command line
Step 1:
In order to run a python script in command line we need a python interpreter that is to be downloaded and installed.
Click here to download Python for Windows.
Click here to download Python for Linux/Unix.
Click here to download Python for Mac OS
Select the python version you want to download (Downloading the latest version is recommended).
Then install the executable file that has been downloaded.
Step 2 :
The next step is to set path variable. To set path follow the following steps:
Go to my computer -> select properties -> select advanced settings -> select environment variable -> new.
In variable name write path and in variable value copy the path of Python interpreter downloaded.
Then click ok
Now path is set for executing python script.
Step 3 :
First we must have a python file to execute.
Open any text editor (Notepad or Notepad++)
Copy the python code give below in the text editor.
print("Welcome to my first program")
Save the file in any folder.
Here I have saved the file in a folder named PythonProgram in D drive.
Step 4 :
Open command prompt.
Type "cd.." in order to change the directory.
Then type the drive name, "D:" for my case.
You'll now get into the folder.
Now type the python file name with ".py" extension.
That's it now you will be able to see the output of the python script which you have executed.
Comments
Post a Comment