Tools to run Python on Android
Python has proven itself as a highly capable language — approachable for newcomers, but powerful in the hands of experts. Why shouldn’t you be able to use Python everywhere that you need to tell a computer to do something? And shouldn’t your tools exploit all the capabilities of Python as a language, not just the bits that map nicely to a C binding?
Modern computing doesn’t happen in an 80x25 console window. It happens on phones, tablets, and desktop machines with rich user interfaces. Shouldn’t you be able to use Python in all those locations, and exploit the unique capabilities of those platforms?
End users shouldn’t have to care what language their tools are written in. And that starts with looking and behaving like completely native tools. Native appearance, native behavior, delivered in the way a native app is delivered. Why shouldn’t your Python tools fit in just as well as a native tool?
There are several ways to use Python on Android.
BeeWare is a collection of tools for building native user interfaces
This is what BeeWare provides. Tools to help you write Python code with a rich, native user interface; and the libraries and support code necessary to get that code running on iOS, Android, macOS, Linux, Windows, tvOS, and more.
The Open Source development process has proven itself to be the most reliable way to develop robust and reliable software. That’s why the entire BeeWare suite of tools are BSD licensed, and available for all to use and modify.
Chaquopy is a plugin for Android Studio’s Gradle-based build system.
Chaquopy enables you to freely intermix Java and Python in your app, using whichever language is best for your needs:
- With the Python API , you can write an app partly or entirely in Python. The complete Android API and user interface toolkit are directly at your disposal.
Chaquopy works within Android’s standard build system:
- If you use Android Studio, you can start using Chaquopy in 5 minutes with no change to your existing development process.
- Download and installation are automated via Gradle.
To get started:
- Try out the demo app for Python 2 or Python 3.
- Browse example source code on GitHub.
- Or view the documentation.
Kivy is a cross-platform OpenGL-based user interface toolkit.
You can run Kivy applications on Android, on (more or less) any device with OpenGL ES 2.0 (Android 2.2 minimum). This is standard on modern devices; Google reports the requirement is met by 99.9% of devices.
Kivy APKs are normal Android apps that you can distribute like any other, including on stores like the Play store. They behave properly when paused or restarted, may utilise Android services and have access to most of the normal java API as described below.
The Kivy project provides all the necessary tools to package your app on Android, including building your own standalone APK that may be distributed on a market like the Play store. This is covered fully in the Create a package for Android documentation.
Using Android APIs
Although Kivy is a Python framework, the Kivy project maintains tools to easily use the normal java APIs, for everything from vibration to sensors to sending messages through SMS or email.
For new users, we recommend using Plyer. For more advanced access or for APIs not currently wrapped, you can use Pyjnius directly. Kivy also supplies an android module for basic Android functionality.
User contributed Android code and examples are available on the Kivy wiki.
Pyqtdeploy is a tool for deploying PyQt applications. It supports deployment to desktop platforms (Linux, Windows and OS X) and to mobile platforms (iOS and Android).
pyqtdeploy works by taking the individual modules of a PyQt application, freezing them, and then placing them in a Qt resource file that is converted to C++ code by Qt’s rcc tool. Python’s standard library is handled in the same way.
pyqtdeploy also generates a Qt .pro file that describes all the generated C++ code. From this Qt’s qmake tool is used to generate a platform-specific Makefile which will then generate a single executable. Further Qt and/or platform specific tools can then be used to convert the executable to a platform specific deployable package.
pyqtdeploy requires PyQt5 and Python v3.2 or later to be installed.
PyQt4 and PyQt5 applications written using Python v2.6 and later and Python v3.3 and later are supported.
pyqtdeploy is released under the BSD license.
QPython is an on-device script engine and development environment.
In most cases, script can get your jobs done as good as the native application. Now you can make it with QPython’s help.
QPython is a script engine which runs Python programs on android devices. It also can help developers develop android applications.
QPython includes a complete development kit which help you to develop programs with mobile provides regular Python console
SL4A (Scripting Layer for Android), originally named ASE (Android Scripting Environment), is a set of “facades” which expose a greatly-simplified subset of the Android API.
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done.
SL4A is designed for developers and is alpha quality software.
PySide (the Python binding for the Qt toolkit) has some preliminary support for Android.
The PySide project provides LGPL-licensed Python bindings for the Qt 4. It also includes complete toolchain for rapidly generating bindings for any Qt-based C++ class hierarchies. PySide Qt bindings allow both free open source and proprietary software development and ultimately aim to support Qt platforms.
Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically — additional packages are available using the APT package manager.
Although Android’s primary programming language is Java, there is no known port of Jython to the platform. Android support in BeeWare is achieved using VOC, a tool that compiles Python source code to Java class files. This allows Python code to be executed as a native binary on the JVM. https://wiki.python.org/moin/Android