Categories
android android-scripting ase jython python

Is there a way to run Python on Android?

2085

We are working on an S60 version and this platform has a nice Python API..

However, there is nothing official about Python on Android, but since Jython exists, is there a way to let the snake and the robot work together??

    1164

    One way is to use Kivy:

    Open source Python library for rapid development of applications
    that make use of innovative user interfaces, such as multi-touch apps.

    Kivy runs on Linux, Windows, OS X, Android and iOS. You can run the same [python] code on all supported platforms.

    Kivy Showcase app

    10

    • 75

      If you use Kivy, here is a tool to help package your project into an APK: github.com/kivy/python-for-android

      – gdw2

      Jan 9, 2012 at 4:42

    • 21

      I’ve been playing around with Kivy this past week attempting to write a game. Their main developers were very quick to answer questions on IRC however if you’ve programmed a GUI before Kivy will make you say WTF quite a bit. Some examples of undocumented things that were weird for me: All widgets get every on_touch_down event even if the event occurred outside their region, No widget has a draw() method, almost everything happens via a custom observer pattern on custom Properties they made up (note these share the name with Python’s property, but are not the same)

      Jan 30, 2012 at 20:41

    • 8

      @Trey: What about non-GUI-related things? Are there any limitations regarding usage of Python’s modules? What about access to Android-specific features, such as ability to read messages, add notification, work in the background, make a photo, read contacts list, determine GPS location etc.?

      – Tadeck

      Mar 24, 2012 at 4:20

    • 8

      And now there is iOS support too!

      – rubik

      Jun 30, 2012 at 7:00

    • 18

      Now, almost a full year later, is support any better? Has here been any notable improvements?

      Nov 17, 2012 at 2:32

    364

    There is also the new Android Scripting Environment (ASE/SL4A) project. It looks awesome, and it has some integration with native Android components.

    Note: no longer under “active development”, but some forks may be.

    6

    • 71

      True, but they have to have ASE installed, it’s not a solution that lets you write an Android app in python without anything already installed (normal user will be all “wtf is this ASE thing?)

      Nov 26, 2010 at 18:30

    • 21

      Further, ASE is a restricted environment; you cannot write full-blown Android apps even if ASE is pre-installed. See stackoverflow.com/questions/2076381

      Jan 23, 2011 at 21:36

    • 11

      I think it was renamed to SL4A.

      – Vanuan

      Dec 4, 2012 at 21:25

    • 10

      You can write apps, package them, and even sell them on Play Store if you like, with SL4A now days. It’s come along well since the comments above were posted. If you want Python on Android, then PY4A, which runs on SL4A is probably the best choice.

      Mar 9, 2013 at 17:53

    • 3

      I confirme, SL4A now permits to write packages of application ready to use, I tried with perl it works

      – ubugnu

      Mar 1, 2015 at 15:32

    229

    Yes! : Android Scripting Environment

    An example via Matt Cutts via SL4A — “here’s a barcode scanner written in six lines of Python code:

    import android
    droid = android.Android()
    code = droid.scanBarcode()
    isbn = int(code['result']['SCAN_RESULT'])
    url = "http://books.google.com?q=%d" % isbn
    droid.startActivity('android.intent.action.VIEW', url)
    

    6

    • 47

      s/YES/meh. maybe/ …it’s extremely limited. anything graphical or multi touch? a big NO.

      – gcb

      Oct 23, 2010 at 9:09

    • 4

      @gcb you can’t use the normal android widget set, but you can use “webviews” (which is what the native gmail application uses, for example).

      – gdw2

      Mar 16, 2012 at 16:10

    • 30

      golfed: import android as a;d=a.Android();d.startActivity('android.intent.action.VIEW',"http://books.google.com?q=%d"%int(d.scanBarcode()['result']['SCAN_RESULT']))

      – Alex L

      Dec 28, 2012 at 6:20

    • 15

      @gdw2, surely the native Gmail app only uses WebViews to parse emails though, not for the actual UI. That makes the comparison a bit absurd.

      Jul 21, 2014 at 21:55

    • @unmounted, when I import android in my python script it says no module named android. when trying to install- pip3 install android I get an error says no module like this. how did you import android o this python script?

      – riki

      Nov 19, 2020 at 10:06