Android : Running Standalone Python

Android Add comments

This is not yet another post on  android-scripting project or SL4A or python for android.

This post is for a specific purpose to empower the terminal again and make users again feel the power of terminal.

Current state we can run perl, python, PHP, ruby, beanshell in SL4A interface or as a standalone apk with modifications.

so here is the bad part

1) you can’t run applications on console directly.

2) you have environmental limitations.

3) you can’t pass command-line arguments.

for a normal person these could be some limitations however for some including myself THESE are the limitations.

so while searching for solution i have came across this script

Here is a modified version of the same making sure the awesomeness embedded

PW=`pwd`
export EXTERNAL_STORAGE=/mnt/sdcard
export LANG=en
PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python
PYTHONPATH=${PYTHONPATH}:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload
export PYTHONPATH
export TEMP=/mnt/storage/com.googlecode.pythonforandroid/extras/python/tmp
export PYTHON_EGG_CACHE=$TEMP
export PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python
export LD_LIBRARY_PATH=/data/data/com.googlecode.pythonforandroid/files/python/lib
cd $PW
/data/data/com.googlecode.pythonforandroid/files/python/bin/python “$@”

highlights are the changes that i made.

These changes allow for following things.

1) allow us to use this shell script to call python.

2) allows for command line argument passing.

3) relative path references are now working

however we also need to understand the importance of Sl4A style project these project provide native applications a direct option to interact / create native UI. (dialog box, button, texts etc)

I have named this script as py and placed it in /system/bin/py location

so basically copying this script in a text file say py.txt

adb push py.txt /system/bin/py

adb shell chmod 04755 /system/bin/py

gives you python shell on your android terminal.

Right now i am working towards making various tools of trade available on terminal.

I will be keeping a track my progress at XDA developer forum thread linked here.

 

3 Responses to “Android : Running Standalone Python”

  1. Atiq Anwar Says:

    Thanx for the info anant, i was stuck to this problem from last 4 months, you solved it… Thanx a ton…

  2. opreat0r Says:

    I got ruby sort of statically compiled … http://rmccurdy.com/stuff/G1/BINS/ some other bins in there too ..

  3. Python in Terminal IDE for Android Says:

    [...] find anything explicit on how to set this up, and then figured out how to use google and found this blog post which links to a script from the p4a (python for android) repository. I’ve reduced the script [...]

Leave a Reply

CommentLuv badge