Python is one of the most popular programming languages. By installing Python inside Termux, you can run scripts, start local servers, practice coding, or even do automation and data analysis directly on your Android device. This guide explains step-by-step how to install, update, and use Python in Termux.
pkg update && pkg upgradeThis ensures everything is up to date.
pkg install pythonThis installs the latest stable release of Python available in Termux repositories.
Note: Termux repositories are updated frequently. If you need the absolute latest release that is not yet available in Termux, you can compile it manually from source (explained below).
-
Install required dependencies:
pkg install build-essential clang python git wget pkg install libffi-dev openssl-dev bzip2 libbz2 libsqlite liblzma
-
Download the latest source code from the official Python website:
wget https://www.python.org/ftp/python/3.x.y/Python-3.x.y.tgz
Replace
3.x.ywith the latest version number. See releases here: https://www.python.org/ftp/python/ -
Extract the archive:
tar -xvzf Python-3.x.y.tgz cd Python-3.x.y -
Configure and compile:
./configure make make install
This way you can run the absolute latest version of Python.
Check Python version:
python --versionor
python3 --versionCheck pip version (Python’s package manager):
pip --versionpythonExample inside the shell:
print("Hello Termux")Exit with:
exit()or press Ctrl + D.
-
Create a file:
nano hello.py
Inside the file, write:
print("Hello, Termux Python!")
Save and exit.
-
Run the file:
python hello.py
- Install a package:
pip install requests
- Upgrade a package:
pip install --upgrade requests
- Show installed packages:
pip list
To manage dependencies per project, use virtual environments.
Create and activate:
python -m venv myenv
source myenv/bin/activateNow all packages will be installed inside myenv.
Deactivate with:
deactivateFor most users, simply running pkg install python is enough to start using Python in Termux. This provides a stable, updated version. If you require the absolute latest release, you can compile it manually from source. With Python inside Termux, you can learn programming, run servers, and develop projects — all from your Android device.