In this post i am going to show you how you can install python in termux. We will install python in termux so one can program in termux with python language. Installing python in termux is much easier than other packages as it is already available in termux package list.
What is Python?
Python Is a high level programming language that can be used to program websites, app and other scripts. This programming language is much easier and fast than other languages. It was designed by Guido Van Rossum. Python is commonly is used in artificial intelligence.
How to install python in termux?
Installation of python in termux is much easier as you do not have to download from external resources. Termux database already contains the python package. One can install python package in a single command but we need to set environment before installing python.
Follow the below steps one by one to Install python in termux:
Step 1: First of all open the termux app. If not installed go to the play store and install it.
Step 2: After opening termux app, type pkg update
Command to update termux packages.
pkg update
Step 3: Type pkg upgrade -y
to upgrade termux packages.
pkg upgrade -y
Step 4: Give storage permissions to termux using termux-setup-storage
command.
termux-setup-storage
Step 6: Install python in termux using pkg install python
-y command.
pkg install python -y
Step 7: Install other python package version using pkg install python2 -y
command.
pkg install python2 -y
Python will start installing in your termux. It will took some time to install python in termux, depends on the phone processor and internet speed. After the installation will be completed you can check it using python --version
command.
python --version
Also Read: How To Install Termux Box In Termux | Latest 2024
How to use Python in Termux?
After installing python in termux. You can use python to write python language codes or you can run scripts of python.
Command 1: Type the below command to start the python and start coding:
python
Command 2: Type the below command to run python file in termux:
python filename.py
Depending on which python version is used in the script the starting version should be set in the starting of the command.
Examples Of Some Python Codes:
A python script that show user the current time.
"""
A script to show the user the current time.
Author: Geek Guy
Email:
Date:
"""
# import the required modules
import datetime
def gettime():
"""
A function to return the current time.
Returns
-------
tuple:
A tuple containing the hour, minutes and seconds.
"""
now = datetime.datetime.now()
return now.hour, now.minute, now.second + 1e-6 * now.microsecond
# get the time
hour, minute, seconds = gettime()
print(f"The current time is {hour}:{minute}:{seconds}")
A python script for implementing switch case options.
# Switcher for implementing switch case options
def employee_details(ID):
switcher = {
"1004": "Employee Name: Geek Guy",
"1009": "Employee Name: Mohsin Farooq",
"1010": "Employee Name: Mujeeb Ashraf",
}
'''The first argument will be returned if the match found and
nothing will be returned if no match found'''
return switcher.get(ID, "nothing")
# Take the employee ID
ID = input("Enter the employee ID: ")
# Print the output
print(employee_details(ID))
Conclusion:
Python is widely used programming language. We have completely learned about the full installation of termux in very easy method. If you find any difficulty in above commands you can tell me through contact us button. Thanks for reading.
Frequently asked questions:
What is python used for?
Python is used to create websites, scripts but mostly used for AI (artificial intelligence)
How many variants are of python?
Currently there is python, python2, python3 available for termux.
What is the short command to install python in termux.
Type pkg install python
 To install python in termux.