How to Install and Use Python in Termux for Beginners

Learn how to run Python in Termux on Android. A beginner-friendly guide for coding, projects, and mobile programming.

Python is one of the easiest programming languages to learn. It is also one of the most popular. If you want to practice Python on your Android device, Termux is the right place to start. Termux gives you a Linux environment inside your phone. With it, you can install Python and run scripts anywhere, anytime. This guide will show you step by step how to install Python in Termux and how to use it as a beginner.

Android phone with Python code showing the word 'Python in Termux'Run Python in Termux

Why Use Python in Termux?

Many people think they need a computer to start programming. But you can start right from your Android phone. Termux makes that possible. Here are some reasons why using Python in Termux is useful:

  • You only need a phone. No computer required.
  • It works even on low storage or budget devices.
  • You can practice coding anywhere, without internet.
  • It’s good for small scripts and automation tasks.
  • You can learn the basics before moving to advanced setups on a PC.

Python inside Termux is not limited. You can still install packages, run scripts, and test small projects. This is enough for learning and practicing.

Step 1: Update and Upgrade Termux

First, update Termux so you don’t face errors during installation. Open Termux and type:

pkg update && pkg upgrade -y

This will refresh all system packages. If you skip this, you may see broken installs later. For other setup tips, check things to do after installing Termux.

Step 2: Install Python

Installing Python in Termux is very simple. Just run:

pkg install python -y

Wait for the installation to finish. To confirm that it worked, check the version:

python --version
Checking Python version

If you see a version number, then Python is ready. For example, it might show something like Python 3.12.11.

Step 3: Open Python Shell

After installation, you can run Python directly inside Termux. Just type:

python

You will see something like:

>>>
Opening Python Shell

This is the Python shell. Here you can write and test Python code line by line. For example, try this:

print("Hello from Termux")

You should see the message printed on your screen. This is the simplest way to run Python commands.

Step 4: Write and Run Python Scripts

Writing code directly in the shell is fine for testing. But if you want to save your code, you should create a Python file. To create a file, type:

nano hello.py

This opens a text editor. Type this code inside:

print("Hello, Termux User!")
Writing code in Python shell

Save the file by pressing CTRL + X, then Y, then press Enter. Now run the script with:

python hello.py
Printing Python text

Your program should display the text you wrote. This is how you create and run Python scripts in Termux.

Step 5: Install Python Packages

Python is powerful because of its packages. With pip you can install extra libraries. Pip comes installed by default in Termux. For example, to install the requests library, run:

pip install requests

After installing, you can import it in your script:

import requests

response = requests.get("https://example.com")
print(response.status_code)

This simple script fetches a website and prints the status code. This is the kind of automation you can do with Termux and Python. You can later move to advanced guides like information gathering once you are confident.

Step 6: Beginner-Friendly Python Projects in Termux

After learning the basics, you can try small projects. Here are a few ideas:

  • Calculator: Write a script that takes two numbers and performs addition, subtraction, multiplication, or division.
  • To-do list: Create a simple text-based to-do list app where you can add and remove tasks.
  • File manager: Write a script that lists files in your Termux home directory.
  • Weather checker: Use an API to fetch weather details for your city.
  • Password generator: Write a script that creates strong random passwords.

These projects help you practice. They also make you comfortable with Python basics like variables, loops, and functions.

You can also try quick Termux projects to boost your learning.

Step 7: Fix Common Problems

Sometimes beginners face errors. Here are common problems and how to fix them:

Problem Fix
Python command not found Re-run pkg install python -y.
Pip not working Update pip: pip install --upgrade pip.
Permission error when saving files Make sure you are inside your home folder: cd ~.
Package install fails Update Termux: pkg update && pkg upgrade -y.

Step 8: Keep Practicing and Manage Your Files

Learning Python is not about reading only. You need to write code daily, even small scripts. For example, you can:

  • Write a program that prints multiplication tables.
  • Write a script that asks for your name and age, then prints a greeting.
  • Write a small guessing game where you guess a random number.

As you write more scripts, it’s better to keep them organized. You can create a folder in Termux:

mkdir python_projects
cd python_projects

If you want to save or load Python files from your phone storage, give Termux permission with:

termux-setup-storage

This will create a storage folder inside Termux. You can find it in /data/data/com.termux/files/home/storage. It links to your phone’s downloads, documents, and pictures. For example:

  • ~/storage/downloads → Phone downloads folder
  • ~/storage/shared → Internal shared storage
  • ~/storage/pictures → Phone pictures

This makes it easy to move Python files between Termux and your regular phone storage for backup or sharing.

Step 9: Use Python for Learning Cybersecurity

Many people use Termux to learn about cybersecurity. Python is one of the most important languages in this field. You can use it for simple automation or to practice safe security projects. For example, you can write scripts that scan open ports on a device or test password strength. These projects are educational and improve your coding skills.

If you want to see an example of security in real life, read this post: Can Hackers Control Self-Driving Cars?. It shows why learning these basics matters. You can also learn about cyber threat intelligence and how it connects to tools you are learning in Termux.

Extra Tips for Beginners

  • Always update your Termux environment. It prevents many errors.
  • Use clear command to clean your Termux screen.
  • Use exit() or Ctrl-D> to leave the Python shell.
  • When stuck, check error messages carefully. They often tell you what went wrong.

Also, remember that you can improve your online safety when learning. Using tools like VPNs with Termux or reading about Surfshark VPN is useful for privacy.

Final Thoughts

Installing Python in Termux is simple. One command gives you a full coding setup on your phone. But the real progress comes when you practice. Write scripts every day, keep them organized, and try small projects that solve real problems.

Termux won’t replace a full laptop, but it removes excuses. You already have the tools in your pocket. The next step is yours—open Termux, type a few lines of code, and keep building your skills.

For more beginner-friendly tutorials, check out Terminal Tools. Each guide is written step by step for learners who want to get better one script at a time.

Post a Comment