Introducing “Python for Android”

I’m glad to share a new project called Python for Android. The goal of this project is to package your python application into an APK.

https://github.com/kivy/python-for-android

The project is under the umbrella of Kivy organization, but is not designed to be limited to Kivy only. Read the documentation to correctly install the NDK/SDK Android, and set the needed environment variables.

The packaging is done in 4 steps:
1. Ensure you have Android SDK/NDK downloaded and correctly installed
2. Ensure you have some environment set
3. Create a Python distribution containing the selected modules
4. Use that distribution to build an APK of your Python application

Creating the python distribution is as simple as that:

A directory dist/default will be created, including the result of the whole arm compilation.
Available libraries as for today: jpeg pil png sdl sqlite3 pygame kivy android libxml2 libxslt lxml ffmpeg openssl.

The second step is a little bit harder, since you need to provide more information for Android:

Then you’ll get a nicely bin/touchtracer-1.0-debug.apk

Pro:

  • A blacklist.txt file that can be used to exclude files in the final APK
  • Reusable distribution for other applications
  • Modular recipes architecture
  • Be able to build independents python distributions

Cons:

  • You need a main.py file that will be used for starting your application
  • Only one java bootstrap available, using OpenGL ES 2.0.
  • Only Kivy toolkit is working. I’m sure that other people can enhance it to add other toolkit recipes. But for example, pygame is not gonna to work because the android project is OpenGL ES 2.0: pygame drawing will not work.

I hope you’ll like it :)

We would like to thank Renpy / PGS4A for its initial pygame for android project

Facebook Twitter Delicious Reddit Digg

41 thoughts on “Introducing “Python for Android”

  1. Pingback: Android » Archive » Introducing “Python for Android” « Txzone

  2. Pingback: Introducing “Python for Android” « Txzone | Dr-Net

  3. Pingback: Introducing “Python for Android” « Txzone | Android News Feed

  4. Pingback: Introducing “Python for Android” « Txzone | WWW.ANDROIDWORLD.BIZ

  5. Pingback: Introducing “Python for Android” « Txzone | Open Hacking

  6. Pingback: Introducing “Python for Android” | So You Want to Build an App...

  7. Can this be used to package Python programs that rely specifically on C libraries? I have something that uses libusb and there’s a libusb-android port that I could compile pyusb against.

  8. Pingback: Introducing “Python for Android” « Txzone | Android情報局

  9. Pingback: Mathieu Virbel: Introducing “Python for Android” | Python | Syngu

  10. Pingback: Introducing “Python for Android” « Txzone | Tech Unleashed

  11. Pingback: Peters Linkschleuder – Der Schockwellenreiter

  12. I know nothing about Android development but I know a little about Python development, so… does this mean that I can code a hello.py app with a single line of code “print ‘hello world’”, build it as APK, install it on my android, and it’ll show “Hello World”?!

  13. Pingback: RP from /programming: Python for Android | QR Code

  14. Pingback: Python for Android – twórz aplikacje dla Androida w języku Python! | Mojdroid.pl – Android dla każdego

  15. Can this be used to package Python programs that rely specifically on C libraries? I have something that uses libusb and there’s a libusb-android port that I could compile pyusb against.

    Yes/no. You might not have the right / possibility to have a direct access of usb (except if you’re root.). But in theory, you would need to write a recipe for libusb-android, pyusb (with a deps on libusb-android), and then: ./distribute.sh “pyusb” => you’ll have python + pyusb + libusb compiled for ARM.

  16. I know nothing about Android development but I know a little about Python development, so… does this mean that I can code a hello.py app with a single line of code “print ‘hello world’”, build it as APK, install it on my android, and it’ll show “Hello World”?!

    No. It will show “Hello World” in the android log (adb logcat), nothing on the screen. This project doesn’t ship any terminal or emulator. If you want to draw something on the screen, you can use the Kivy toolkit (take the hello world from the frontpage kivy.org), then ./distribute.sh -m “kivy”, and package your app, you’ll see the hello world button.

  17. Looks awesome. How hard would it be to combine with Pyside for android, described on http://thp.io/2011/pyside-android/?

    I think it’s just a matter of writing a recipe for it (and all the deps not in the project yet) + create a java bootstrap for it (maybe not, dunno about this project.)

  18. Pingback: Новости компьютерного мира - Инструментарий для разработки приложений на языке Python для платформы Android

  19. Pingback: Инструментарий для разработки приложений на языке Python для платформы Android

  20. Pingback: Инструментарий для разработки приложений на языке Python для платформы Android | AllUNIX.ru — Всероссийский портал о UNIX-системах

  21. Pingback: Kivy ha creato Python for Android, un nuovo ambiente per lo sviluppo | Open Source

  22. Pingback: Projeto Python para Android é lançado | F2 - Sistemas

  23. Pingback: Kivy ha creato Python for Android, un nuovo ambiente per lo sviluppo | Indipedia – Indipendenti nella rete

  24. Pingback: Kivy ha creato Python for Android, un nuovo ambiente per lo sviluppo | Tuttolinux - novità ed articoli dal mondo del pinguino !

  25. Pingback: Sviluppare per Android con Python | Edit - Il blog di HTML.it

  26. Pingback: Mannix все о nix OpenSource

  27. Pingback: Kivy ha creato Python for Android, un nuovo ambiente per lo sviluppo | Khriss.com

  28. Is there a tutorial out there that shows a “Hello World”, start to finish, including compilation as an APK and testing on both an Android device and an emulator?

    I’d love to do some development on Android, but I have no desire at all to learn Java’s syntax.

  29. Pingback: Python para Android é Lançado | Blog Seja Livre

  30. How does this approach compare with Py4A (Python for Android http://code.google.com/p/python-for-android/) via SL4A (Scripting Layer for Android http://code.google.com/p/android-scripting/)?

    I have managed to cross-compile shared libraries and load them up via ctypes without being root going down this path. The tricky part is the cross-compilation. I am most intrigued that someone has compiled PIL for android. I have had some relatively but hasty yet futile attempts.

  31. Seems something different from Py4a, but is is really awesome. With py4a, we could use use browser as GUI by android.webview().

    In the latest IPython (1.2), it supports “notebook()”, a html interface to python programming. This is what I try for making android app. With this “Python for Android”, I had compiled the required dependencies of IPython, uuid, zeromq, pyzmq, tornado; but failed in compiling IPython. Before successfully compiling Ipython, this is one question: is it possible to write a simple python staff to startup notebook(), waiting for services via browser?

    Thanks in advanced,

  32. Pingback: IOS Support for Kivy | Txzone

  33. There is any hope that the building process for a Python project to an Android device with “Python for Android” could be the same as Pyinstaller does?

  34. Pingback: Using Python to get pixel value of a jpeg(SL4A android 4.0) : Android Community - For Application Development

  35. import android
    app = android.Android()

    app.view(“file:///storage/sdcardo/DCIM/Facebook/IMG_1180747574817.jpeg”,”image/*”)

    jpg=PIL.Image.open(‘/storage/sdcard0/DCIM/Facebook/IMG_1180747574817.jpeg’)
    pixels = jpg.load()
    r,g,b = pixels[x, y]

    I try to run this python script on my android device
    but this error appeared
    PIL is not defined
    I try to use your code but I can’t ,can tell me how to defined PIL

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">