Run Python Scripts in Termux: python, pip and a .py File
Turn Termux into a small Python workshop: install the wiki’s python package (pip is included), write a .py file, run it, and install a module with pip. F-Droid Termux assumed. Educational scripting only—nothing that bypasses phone security or other people’s systems.
What You Need
- F-Droid Termux with internet (for packages and optional pip modules).
- Optional editor:
pkg install nano(from our pkg install lesson).
Install Python → write → run → pip
Step 1: Install python
Termux wiki:
pkg install pythoninstalls Python 3.x. Pip ships with it—no separate pip package.pkg update pkg install python python --version pip --version
Step 2: Create a project folder and .py file
mkdir -p ~/projects/hello-py cd ~/projects/hello-py nano hello.py
Paste (or type) this sample, then save with Ctrl+X, Y, Enter:
print("Hello from Termux") name = "Byteslip" print(f"Learning Python on {name}")Step 3: Run the script
python hello.py
You should see two lines of output. Fix typos in
nano hello.pyand re-run. Prefer keeping scripts under~/projects(private Termux storage), not shared/sdcard.Step 4: Install a module with pip
Wiki package management for Python modules:
pip install requests python -c "import requests; print(requests.__version__)"
For modules that compile native code, the wiki recommends
pkg install build-essentialfirst. Prefer Termux-packaged Python libs when listed on the wiki (e.g.pkg install python-numpy) over fighting pip builds.Step 5: Use the module in a script
nano fetch_example.py
import requests r = requests.get("https://httpbin.org/get", timeout=15) print("status", r.status_code) print(r.json().get("url"))python fetch_example.py
Only call sites you’re allowed to use. Uninstall a module later with
pip uninstall requests.
- Python: wiki.termux.com/wiki/Python
- Package Management: wiki.termux.com/wiki/Package_Management