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 helloworld.py which was in the current working directory we would do it like this:
python helloworld.py
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:
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.