How to create a python file in Termux

Python is a popular programming language used in various fields such as machine learning, data science, and web development. Termux is an Android terminal emulator and Linux environment app that allows you to run command-line utilities and install packages on your Android device. In this article, we will show you how to create a Python file in Termux.

Step 1: Install Python in Termux

Before creating a Python file, you need to install Python on your Termux. To do this, open your Termux app and type the following command:

pkg install python

This command will install the latest version of Python on your Termux. If you already have Python installed, you can skip this step.

Step 2: Create a Python File

Once you have installed Python, you can create a Python file using any text editor of your choice. In this example, we will use the Nano text editor to create a Python file named “”. To create a new file, type the following command:


This command will open a new Nano editor window where you can write your Python code. You can write any Python code in this file, but for this example, we will write a simple “Hello World!” program.

print("Hello World!")

Step 3: Save the Python File

Once you have written your Python code, you need to save the file. To save the file, press Ctrl + X to exit the Nano editor. You will be prompted to save the changes you have made to the file. Press Y and then Enter to save the file.

Step 4: Run the Python File

To run the Python file you have just created, type the following command:


This command will execute your Python program and output the result “Hello World!” in the terminal.

Table of Commands:

pkg install pythonInstalls Python on your Termux
nano example.pyOpens a new Nano editor window to create a new Python file
Ctrl + XExits the Nano editor
YConfirms the changes you have made to the file
python example.pyExecutes the Python program you have just created


Creating a Python file in Termux is a simple and straightforward process. By following the steps outlined in this article, you can quickly create and run Python code on your Android device. With Python installed on your Termux, you can take your Python programming skills on the go and work on projects from anywhere.

Leave a Comment