Python (statically compiled) for Android (ARM)

+2 jan burg · December 3, 2014
Hey guys I thought I'd let you all know I finally got python compiled statically for Android as a standalone command line interpreter. This is basically just a copy of a post I made at xda-developers ( I'd really like to get this tested on some more devices, so if you're interested, please check it out. Thanks!

Recovery flash installers are linked at the end that will install python 2.7.8 and/or 3.4.2 to /system/pythonX.X.X. You can install both if you want. Installation size is about 78MB for python 2.7.8 and 110MB for python 3.4.2.

After installation, the python director(ies) in /system will contain the static python binary, the python library.a, and a bunch of modules and documents. Separate scripted executables will be installed to /system/bin/python or /system/bin/python3 depending on which one is installed. These basically just set the PYTHONHOME environment variable and execute the python binary.

When you boot up to Android after installation, you should be able to just open up a terminal and fire off some python commands.

Test using python 2.7.8:

python -c 'print "Hello World!"'

Test using python 3.4.2:

python3 -c 'print("Hello World!")'

You can also write scripts shelled with python:


print "Hello World!"

Make sure to set them as executable with "chmod +x".

Adjust your screen brightness via /sys (root required, tested on Galaxy Nexus):

python -c 'f=open("/sys/devices/omapdss/display0/backlight/s6e8aa0/brightness","w"); f.write("40"); f.close()'

A cool script I made to tweak file system I/O like rq_affinity, rotational, etc for I/O blocks:


import os,re,sys

# find all directories containing rq_affinity
for roots, dirs, files in os.walk('/sys'):
  for file in files:'\S+/rq_affinity',os.path.join(roots,file))
    if match:

# write specific values to files in each directory found before
for dir in list:
  for name in 'rq_affinity', 'rotational', 'read_ahead_kb', 'nr_requests', 'iostats', 'nomerges', 'add_random':
      if name is 'rq_affinity': f.write('1')
      elif name is 'read_ahead_kb': f.write('512')
      elif name is 'nr_requests': f.write('512')
      else: f.write('0')
    except IOError:
      sys.stderr.write('Problem writing to ' + dir+name + '\n')

Or execute "python" or "python3" without any parameters to open up the interpreter and go from there. When you start for example "python" (python 2.7.8), you should see something like:

Python 2.7.8 (default, Dec  1 2014, 05:15:18) 
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.

***I haven't fully tested this yet, so let me know how it goes. I know basic commands work, but there are still some complexities in the compilation that may need to be figured out.***

The python installations have the following modules not compiled in:

--------------PYTHON 2.7.8-----------------------------
_bsddb             _ctypes            _ctypes_test    
_hashlib           _hotshot           _json           
_lsprof            _multiprocessing   _sqlite3        
_ssl               _testcapi          bz2             
crypt              dbm                future_builtins

--------------PYTHON 3.4.2-----------------------------
_bz2                  _crypt                _ctypes            
_ctypes_test          _dbm                  _decimal           
_gdbm                 _hashlib              _json              
_lsprof               _multiprocessing      _opcode            
_sqlite3              _ssl                  _testbuffer        
_testcapi             _testimportmultiple   ossaudiodev 

-Compiled in more modules for each installation. This makes the installation a bit bigger, but it's worth it. You get a more complete python! :)

deprecated( python 2.7.8 large: )
deprecated( python 3.4.2 large : )

NON-EDIFY Installers in case the one above fail:
python 2.7.8 large :
python 3.4.2 large :

Post a Reply


Oldest  Newest  Rating
+1 jan burg · December 4, 2014
Thanks man. Yeah let me know how it goes. I'm working on getting the missing modules listed compiled, already got a few. Then I'm just writing scripts to run on Android. Already had a day of fun there yesterday!
+1 Doug Fresh · December 4, 2014
Very nice! There goes my weekend of fun, code testing time.
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator