Run Python Script Linux (Ubuntu) Command Line
You can run Python script through Linux command line.
It is a great feature of using Linux kernel base Operating System like Ubuntu, Linux Mint etc that you can easily run or compile Python file through Linux Command Line without installing any IDE for Python Language. Not only Python File, you can interpret Python statement on Terminal.
So this tutorial will let you learn -
When your text editor is ready then write your Python code and Save.
To run Python File on Terminal:
It is a great feature of using Linux kernel base Operating System like Ubuntu, Linux Mint etc that you can easily run or compile Python file through Linux Command Line without installing any IDE for Python Language. Not only Python File, you can interpret Python statement on Terminal.
- How to create Python File on Terminal.
- How to run Python File on Terminal.
- How to write Python code and run on Terminal.
- Tips to write Python code on Terminal
- Open Terminal by Ctrl + Alt + T
- Open any Text Editor and create a Python file with
file_name.py
. If you have Sublime Text Editor then write the following command and hit Enter.subl file_name.py
If you don't have any then write the following command and hit Enter.gedit file_name.py
By default, Ubuntu has Gedit Text Editor.

When your text editor is ready then write your Python code and Save.
To run Python File on Terminal:
- Open Terminal by Ctrl + Alt + T, if it is opened, then no need to reopen.
- First check your current directory of created Python file.
To check directory run the following command.
pwd
- Then change the directory to your python file
file_name.py
. Suppose your current directory of your created file is/home/you/Desktop
, then run the following command.cd /home/you/Desktop
- After changing directory from Terminal, put the following command.
python file_name.py
file_name.py
is the name of your Python file. You will see the output of your python file.
To write Python Code and Run on Terminal:
- Open Terminal by Ctrl + Alt + T, if it is opened, then no need to re-open.
- Type Python and hit Enter
- Now write Python code and hit Enter to next statement.
- To copy and code on Terminal first select by mouse and Ctrl + Shift + C to copy and Ctrl + Shift + V to paste.
- Since Indention is the most important for Python Programming Language, Put Spacebar twice when Indention is needed. Example:
- >> Type
8 + 3
and hit Enter, you will see result 11 - >> Type
list = [3, 4, 2, 5]
and hit Enter. Again Type list and hit Enter, you will seelist = [3, 4, 2, 5]
- >> Go on.
Have got this article helpful or not working? Put your comment below.