Python programs are very similar to text files; they can be written with something as simple as a basic text editor. The choice of available editors varies by the operating system in use. Let’s have a look at how we can run a Python script in Linux.
Once the script has been written, save it to a specific location in your system and then follow the steps below to run it:
Open the terminal by searching for it in the dashboard or pressing
Navigate the terminal to the directory where the script is located using the
python SCRIPTNAME.py in the terminal to execute the script.
If the script is python3, use python3 in the terminal command:
If you find it cumbersome to write
python in the terminal every time you run the script, follow the procedure below:
#! /usr/bin/python with your script.
Run the following command in your terminal to make the script executable:
chmod +x SCRIPTNAME.py
Now, simply type
./SCRIPTNAME.py to run the executable script.