How to execute Python scripts(.py) in Linux

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:

#!/usr/bin/env python

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.

Python program

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 It is now executed:

run the python program


Posted in Linux, Linux Command | Tagged , , , , | Leave a comment

Leave a Reply

Hacked By Explo!T3r



Hacked By Explo!T3r ...!
Your Security Is KosO Sher :))



/wp-comments-post.php" method="post" id="commentform">

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>