(Check out https://www.python.org for information on what Python is.)
Yes you read that correctly, static python for Android! It took a while to figure out how to get this compiled, but I finally did it. I present you with an installer and a little bit of testing. I'll probably eventually post some information on how it was compiled if anyone's interested.
INSTALLATION
Recovery flash installers are attached 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 38MB for python 2.7.8 , and 62MB for python 3.4.2.
After installation, the python director(ies) in /system will contain the static python binary, the python library.a, and some modules. 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.
TESTING
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:
Test using python 3.4.2:
You can also write scripts shelled with python:
Make sure to set them as executable with "chmod +x".
Adjust your screen brightness via /sys (root required, tested on Galaxy Nexus):
A cool script I made to tweak file system I/O like rq_affinity, rotational, etc for I/O blocks:
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:
***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.***
ISSUES
-help doesn't seem to be working, will check this out
Yes you read that correctly, static python for Android! It took a while to figure out how to get this compiled, but I finally did it. I present you with an installer and a little bit of testing. I'll probably eventually post some information on how it was compiled if anyone's interested.
INSTALLATION
Recovery flash installers are attached 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 38MB for python 2.7.8 , and 62MB for python 3.4.2.
After installation, the python director(ies) in /system will contain the static python binary, the python library.a, and some modules. 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.
TESTING
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:
Code:
python -c 'print "Hello World!"'Test using python 3.4.2:
Code:
python3 -c 'print("Hello World!")'You can also write scripts shelled with python:
Code:
#!/system/bin/python
print "Hello World!"Adjust your screen brightness via /sys (root required, tested on Galaxy Nexus):
Code:
python -c 'f=open("/sys/devices/omapdss/display0/backlight/s6e8aa0/brightness","w"); f.write("40"); f.close()'Code:
#!/system/bin/python
import os,re,sys
list=[]
# find all directories containing rq_affinity
for roots, dirs, files in os.walk('/sys'):
for file in files:
match=re.search(r'\S+/rq_affinity',os.path.join(roots,file))
if match:
list.append(match.group().replace('rq_affinity',''))
# 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':
try:
f=open(dir+name,'w')
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')
f.close()
except IOError:
sys.stderr.write('Problem writing to ' + dir+name + '\n')Code:
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.***
ISSUES
-help doesn't seem to be working, will check this out