You can execute python scripts in Linux directly using the terminal. For both programmers and users, it can be very useful. It’s simple to run the python program in the Linux terminal. You just need to do couple of things. You can create a .py a program yourself and you may have already .py program but don’t know how to run it. Let’s start:
You need to put this following line in your python script:
which means the script will execute with the help of env python in usr/bin directory.Here’s the simple python program I have created.
Now, make the file executable by adding the permission using:
chmod ugo+rwx which adds all three: read, write and execute permission to all the three users: users, group and others. If you are confuse about adding permission take a look at how to add and remove permission to files and directories in Linux.
Now, execute the file using:
The file I have created is hello.py. It is now executed: