No laptop? No problem. Python in Termux makes mobile development a breeze.
Python in Termux changed the way I saw coding education. Years ago, I ran a tech tutorial YouTube channel. Soon, I had subscribers from all over the world, eager to learn programming. I built my lessons assuming everyone had access to a full computer.
But I was wrong.
One day, a student from India messaged me: “I love your tutorials, but I only have a mobile phone. Can I still learn Python in Termux?” At first, I thought it was an exception. Surely, most aspiring programmers had laptops or desktops?
Then, reality hit me. More students reached out, all saying the same thing: they wanted to learn Python, but all they had was a phone. A young programmer in Nigeria even admitted to stealing a mobile phone from a foreigner—just so he could submit his assignments. That moment shattered my assumptions.
I had unknowingly built content for a privileged audience, overlooking the vast majority of students struggling to code without a computer. That’s when I discovered Python in Termux.
A computer may be out of reach for many, but almost everyone has a mobile device. With Python in Termux, you don’t need an expensive laptop to start coding. You can install Python, write scripts, and even manage projects—all from your Android phone.
In this guide, I’ll show you exactly how to install Python in Termux like a pro, avoid common mistakes, and set up a virtual environment for better project management.
Download my FREE Python Infographic Now!
Why Install Python on Android?
Not everyone has access to a laptop or desktop computer, but nearly everyone has a smartphone. In many countries, students rely entirely on mobile devices for learning, making traditional programming education inaccessible. Python in Termux bridges this gap, allowing aspiring coders to write and run Python scripts directly on their phones.
When I first started creating coding tutorials on YouTube, I assumed my audience had access to full computers. But as messages poured in from students across the world, I realized how many were trying to learn Python using nothing but a mobile phone. Some had no other option. One student in Nigeria even confessed that he had stolen a phone just to keep up with his assignments. That revelation shook me.
That’s when I discovered Python in Termux—a lightweight but powerful way to run Python on Android. It enables students, hobbyists, and professionals to code anywhere, without needing a traditional computer. With Python in Termux, they can install libraries, manage virtual environments, and even build real-world projects—all from their smartphones.
For many students worldwide, Python in Termux isn’t just a convenience; it’s their only gateway to programming. It levels the playing field, allowing anyone with a smartphone to start coding today.
· · ─ ·𖥸· ─ · ·
Before You Begin: A Quick Note on Termux and Linux
If you’re new to Termux or the Linux command line, don’t worry—you’re not alone. Termux is a powerful terminal emulator that brings a full Linux-like environment to Android, but it can feel unfamiliar if you’ve never used a command-line interface before.
Before proceeding, I highly recommend checking out How to Install Termux on Android: Run Linux Like a Pro (No PC Needed!) to get a solid foundation. That guide covers everything from installation to essential commands, ensuring you’re comfortable navigating Termux before diving into Python setup.
Now, let’s move on to installing Python in Termux the right way!
· · ─ ·𖥸· ─ · ·
Installation Procedure:
Step 1: Update Termux Packages
Before installing Python, it’s essential to update the Termux package list to ensure you have the latest versions of all available packages. Open Termux and run the following command:
pkg update && pkg upgrade
Step 2: Install Python in Termux
Now that your Termux environment is up-to-date, you can install Python. Execute the following command to install Python in Termux:
pkg install python
This command will install Python and its package manager, pip
, which you can use to install additional Python packages.
Step 3: Verify the Python Installation
After the installation is complete, verify that Python is installed correctly by checking its version. Run:
python --version
You should see the installed Python version displayed on your screen, confirming that Python is successfully installed in Termux.
Step 4: Install Python Packages Using pip
With Python installed, you can now use pip
to install additional packages. For example, to install the popular requests
library, run:
pip install requests
You can install any other Python packages you need using pip
.
Step 5: Setting Up a Virtual Environment
Creating a virtual environment is a best practice for managing dependencies for different projects. Here’s how to set up a virtual environment in Termux:
pip install requests
Install virtualenv
: First, install the virtualenv
package using pip
:
pip install virtualenv
Create a Virtual Environment:Create a new virtual environment by running:
virtualenv myenv
Replace myenv
with the name you want for your virtual environment.
Activate the Virtual Environment:To use the virtual environment, activate it with:
source myenv/bin/activate
Your prompt will change to indicate that the virtual environment is active. You can now install packages specific to this environment without affecting your global Python setup.
Deactivate the Virtual Environment:When you’re done working in the virtual environment, deactivate it with:
deactivate
Your prompt will return to its normal state.
Step 6: Create and Run a Python Script
To ensure everything is working correctly, let’s create a simple Python script and run it. Use a text editor to create a new file named hello.py
:
nano hello.py
Add the following code to the file:
print("Hello, Termux!")
Save the file and exit the editor. Run the script with:
python hello.py
You should see “Hello, Termux!” printed on the screen, indicating that your Python setup and virtual environment are working correctly.
· · ─ ·𖥸· ─ · ·
Common Mistakes to Avoid When Installing Python in Termux
Installing Python in Termux is straightforward, but many beginners encounter avoidable issues. Here are the most common mistakes and how to prevent them:
1. Skipping Termux Updates
Before installing Python, always update Termux’s package list. Skipping this step can lead to broken dependencies or outdated versions. Run:
pkg update && pkg upgrade -y
This ensures you are working with the latest software versions.
2. Installing Python Without Required Packages
While pkg install python
is the main command, some projects require additional dependencies like pip
or clang
. To avoid issues later, install everything upfront:
pkg install python python-pip clang -y
3. Not Using a Virtual Environment
Installing packages globally can lead to conflicts between projects. Always create a virtual environment to keep dependencies organized:
python -m venv myenv
source myenv/bin/activate
This keeps your Python setup clean and avoids compatibility issues.
4. Using the Wrong Python Command
Termux installs Python as python
, but some users mistakenly type python3
or python2
. Always verify the correct command with:
python --version
If you need Python 3 specifically, Termux already installs it by default.
5. Manually Editing Termux Files Without Understanding Them
Avoid manually modifying system files inside Termux unless you fully understand what you are doing. If something breaks, resetting Termux is often easier than troubleshooting:
rm -rf $HOME/.termux
6. Ignoring Storage Permissions
If you need Termux to access files outside its own directory, you must grant storage permissions:
termux-setup-storage
Without this, you may run into issues when trying to save or read files from shared storage.
Conclusion
By installing Python in Termux and setting up a virtual environment, you unlock the ability to code anytime, anywhere—without needing a traditional computer. Whether you’re automating tasks, developing scripts, or learning Python for the first time, Python in Termux transforms your Android device into a powerful coding tool.
For many aspiring programmers worldwide, mobile coding isn’t just a convenience—it’s a necessity. With the right setup, you can write, test, and manage Python projects efficiently, all from your phone. Follow these steps to get started, avoid common pitfalls, and take full advantage of Python in Termux as your mobile development environment.
Now that your setup is ready, what will you build first? 🚀
Leave a Reply