BYTESLIP ← Back
Knowledge Base // Tutorial 58 · Termux

Run Python Scripts in Termux: python, pip and a .py File

Difficulty: Medium ~10–20 min Termux · F-Droid

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.

Python in Termuxpkg install pythonpython hello.py · pip install requestswiki: Python · Package_ManagementMEDIUM · PYTHON SCRIPTS
Checklist // Before You Start

What You Need

Walkthrough // Steps

Install Python → write → run → pip

  1. Step 1: Install python

    Termux wiki: pkg install python installs Python 3.x. Pip ships with it—no separate pip package.

    pkg update
    pkg install python
    python --version
    pip --version
  2. 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}")
  3. Step 3: Run the script

    python hello.py

    You should see two lines of output. Fix typos in nano hello.py and re-run. Prefer keeping scripts under ~/projects (private Termux storage), not shared /sdcard.

  4. 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-essential first. Prefer Termux-packaged Python libs when listed on the wiki (e.g. pkg install python-numpy) over fighting pip builds.

  5. 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.

Sources // Verified
← All Tutorials Termux tutorials Install Termux