Open In App

Open and Run Python Files in the Terminal

Last Updated : 15 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The Linux terminal offers a powerful environment for working with Python files, providing developers with efficient ways to open, edit, and run Python scripts directly from the command line.

Open and Run Python Files in the Linux Terminal

In this article, we’ll explore various techniques and commands for handling Python files in the Linux terminal, empowering developers to streamline their workflow and enhance productivity.

Steps to Open, Edit, and Run Python Files in the Terminal

1. Open the Ubuntu Terminal

2. Use the cd command to change the present working directory to the directory in which the Python program file is saved or in which you want to create the program file.

cd Documents/Programs/
changing present working directory using cd command in Ubuntu

changing the present working directory using the cd command in Ubuntu

3. Use the vim command to open/create the file. It will open the editor where you can write the code.

vim hello.py
Screenshot-from-2024-02-03-04-14-01

Open hello.py in Vim

Here, you can learn to use the basic commands of Vim which will help you to comfortably write you code. to save and exit use the following step:

  1. Press ESC
  2. Press :wq
  3. This will save and quit the VIM Editor.
Screenshot-from-2024-02-03-04-15-58

writing the Python code

4. After saving the file run the Python program by using the following command.

python3 hello.py
Screenshot-from-2024-02-03-04-26-21

run the Python program


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads