This blog has permanently moved to

Contact Form | Email Address

© 2018 All rights reserved by Boseji

Thank you for all your support.

Friday, July 1, 2011

Scripting Android(SL4A) with Python on LG Optimux P500

We got our first Android Phone LG Optimus P500 with Android 2.2 Version. This phone has 512MB of internal RAM which is good to give a decent performance. We did not limit us to this, we wanted to make some good use of this mobile. So the Idea came that we can try to have a programming environment right int the Android Phone.
We knew that there is a complete development environment available to use PC as the host and develop applications for Android. But we wanted some thing easier. Something that could help us get Python on Mobile.
We found Scripting Layer for Android brings scripting languages to Android. SL4A in short.

Scripting Layer for Android (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.
Scripts can be run interactively in a terminal, in the background, or via Locale. Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported, and we're planning to add more. See the SL4A Video Help playlist on YouTube for various demonstrations of SL4A's features.
We wanted Python so we went for Py4A - Python for Android.
This is the version of Python that's built to Run with the SL4A and includes various functionality such as Blue-tooth Encryption etc.

Here is a list of files that you need to download:
sl4a_r4.apk: The SL4A Frontend

textedit-sl4a.apk: Editor for the scripts

PythonForAndroid_r5.apk: Python Interpreter for SL4A (Or the latest version available)

Python Modules:



Now after you have all these files in the Phone in a separate Directory say "/sdcard/Develop/"
You are ready to go for the Installation.

Steps for Install:
- Install the sl4a_r4.apk File (Make sure you have install from Unknown source option enabled in settings)
- Install the textedit-sl4a.apk and PythonForAndroid_r5.apk
- After this transfer the SL4A and TextEdit applications to SD card from settings
- Open the Python for Android App and click on Install
   (The App would now download the nessary files automatically. So make sure you have your internet connection ON in the mobile)
- After the Extraction is done it would show that the installation has been successful, Now click on Import Modules and sequentially install the modules one after another. (All three of them)
- Exit the Python for Android App and then run the SL4A app to get the SL4A Frontend running.
  (Dont miss this else like in the Video the programs wont run)
- Now go back to Home screen keeping the SL4A running in background - Run the Text Edit App
- Browse the SD Card for "sl4a" folder in which the "scripts" directory contains the "HelloWorld.py"
   (should be "/sdcard/sl4a/scripts")
- Now you can edit the file and save it
- Go back to Home screen and Open the SL4A app again. Click the Option button to refresh the files
- Single click on the HelloWorld.py shows the activity bar. (this contains the "Terminal Run" or "Edit" Options)
- Click on the Terminal icon to Run the Modified HelloWorld.py
- You see a terminal window automatically pop out and then says "Hello World"
- Now you would be prompted to Exit the Terminal so click "Yes
That's It - You have successfully executed your first Python Script on Mobile.

Here is the Video that Demonstrates all procedures after the Files are Downloaded:


  1. sl4a app could not recognise *.py scripts. how could i execute it? i am using samsung galaxy 3 i5801

  2. Hello,
    We have specified the procedure and the order of the installation in the post. Thus if you have installed the Py4A before SL4a it should work. Else you can also install the Interpreter from SL4A. Select the option button on the first screen and then select "Add". Now select "Interpreter" and select "Python".
    Let us know if this works.
    Warm Regards,