how to run Python scripts on Linux OS

Posted by

Basically, when you are running scripts [python / bash / sh] etc. you will need to check some specs before you run it, at this time the focus is on Python scripts.

#1 Check if the file has the specific “shebang” line as first line of the script.

What is “shebang” ? It’s a simple line that act as variable into the script to indicate the location of the Python interpreter on the system.

For example,


Note: Check the syntax, if does not have the correct order it will fail.

#! /path/to/python/interpreter

#2 Check permissions of the script, the script will need execute permissions.

For example,

-rwxr-xr-x. 1 root root 0 Jan 31 00:12

You can assign execute permissions to the script with the following command,

[root@localhost ~]# chmod +x filename.extension

Note: Extension, because the command works to assign execute permissions to any type of scripts.

[root@localhost ~]# chmod +x

#3 Now you only need to run the script, to do that just type the word “python” at the beginning of the script you want to run and wait until the task is done. That will invoke the python interpreter located on the specific path we used as shebang.

[root@localhost ~]# python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s