How to run Python script in Ubuntu Linux

In this tutorial, you will learn how to run Python scripts in Ubuntu using the terminal. The process basically involves invoking the Python interpreter and passing the name of the Python script to be executed as an argument to it.

This tutorial also covers how to install Python if it is not currently installed on your system.

So if we wanted to use the terminal to invoke a Python script called which was in the current working directory we would do it like this:


The script would then run and execute the instructions that were contained in it.

If you get the following error or something similar it means you probably do not have Python installed on your system:

-bash: python: command not found

To check if you have Python installed, from a terminal execute the following:

which python

You should get:


If you don't get any output, it means that Python is not installed. If you are on Debian/Ubuntu Linux, installing Python is as simple as executing the following command as root:

apt-get install python

And that is it. Once you have Python installed, you should now be able to execute Python scripts on your machine.

We hope you found this Python tutorial useful.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...