PyBox / Blog / How to

How to run Python on Android: four ways, with steps

You can run real Python on an Android phone or tablet without rooting it. Here are four routes, from easiest to most flexible.

How to run Python on Android: four ways, with steps: the PyBox screen this guide uses
PyBox is the Python IDE I build. Everything below works with it, and the steps are the same ideas you would use anywhere. Get it on Google Play.

1. An IDE app with an embedded interpreter

The quickest path. Install the app, open a template and press Run. In PyBox that looks like this:

  1. Install PyBox and let it unpack its runtime once.
  2. Tap New Project and pick a starter such as Python Basics Tour.
  3. Press Run. Output appears in the terminal.

Add packages by listing them in requirements.txt and tapping Sync Project, or run pip install requests in the terminal.

2. Termux

Termux is a Linux terminal for Android. Install it, then:

pkg update
pkg install python
python --version
pip install requests

You then edit files with nano or vim, or from another app. It is flexible but has no editor intelligence of its own, and GUI toolkits need extra setup.

3. A Chromebook's Linux container

On a Chromebook with Linux enabled you get a Debian environment where sudo apt install python3 python3-pip works. It is the most desktop-like route, but only for Chromebooks.

4. Cloud notebooks

Browser services run your code on a server. You need a connection, and your code and data leave the device. That can be right for heavy jobs and wrong for private or offline work.

Which to pick

OfflineSetupGUI apps
IDE appYesMinutesDepends on the app; PyBox has an X11 desktop
TermuxYesSomeNeeds extra setup
Chromebook LinuxYesSomeYes
Cloud notebookNoNoneNo

For most people, an IDE app is the right start. When you outgrow it, add Termux.

Your first script, step by step

  1. Install an app from the list above and open it. Wait for the first-launch setup to finish; a runtime that unpacks itself only does this once.
  2. Create a file called hello.py.
  3. Type the program below and run it.
import sys, platform
print("Hello from", platform.system(), platform.machine())
print("Python", sys.version.split()[0])
for n in range(1, 6):
    print(n, n * n)

If it prints the squares, the interpreter works. Then try pip install requests to confirm packages install.

If something does not work

  • The app will not install. Check the Android version and the CPU type. PyBox needs Android 8.0 or newer on arm64 or x86_64.
  • It stays on the setup screen. Keep the app open until the one-time unpacking ends, and make sure the device has free storage.
  • pip fails on a package. Packages with native code need a build made for Android. Pure Python packages install from PyPI as usual.
  • A GUI program shows nothing. Android has no display server by default, so Tkinter, pygame and Kivy need an app that provides one.

Questions

Do I need to root my phone to run Python?

No. Apps like PyBox and Termux run Python without root.

Can I run Python on Android offline?

Yes, with an app that embeds the interpreter. You need a connection only to download packages.

Anshuman MishraBuilds PyBox at Vytros, a Python IDE for Android. About the developer.

Code Python on your phone.