Run Python in Android terminal

I have Android 5.1 CM12 (root, supersu, busybox) and am trying to access Python for Android (PythonForAndroid_r5.apk) from an Android terminal.

I follow this guide: http://lifepluslinux.blogspot.de/2015/01/installing-python-on-android-50.html

this is the script i am using (python2):

    export EXTERNAL_STORAGE=/mnt/sdcard

    PYTHONPATH=${EXTERNAL_STORAGE}/com.googlecode.pythonforandroid/extras/python
    PYTHONPATH=${PYTHONPATH}:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload
    export PYTHONPATH
    export TEMP=${EXTERNAL_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
/data/data/com.googlecode.pythonforandroid/files/python/bin/python "$@"

python2 and sh are on the / bin / system

but when I execute these script, I get:

C:\Users\bla>adb shell python2
: not found/python2[2]:
: is not an identifier: export: PYTHONPATH

What can you tell me about this mistake! And how to fix it?

+4
source share
1 answer

I played for a while, and finally I got his job. my script (python2 located on the / bin system):

export EXTERNAL_STORAGE=/mnt/sdcard
export PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6
export TEMP=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/tmp
export PYTHON_EGG_CACHE=$TEMP
export PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.googlecode.pythonforandroid/files/python/lib:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload:/mnt/sdcard/com.googlecode.pythonforandroid/extras/python
/data/data/com.googlecode.pythonforandroid/files/python/bin/python "$@"

In Android terminal:

u0_a101@C1905:/ $ su
root@C1905:/ # python2

Now it works to enable Python2.7 in Android 5.1 Terminal!

dlopen libpython2.6.so
Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21)
[GCC 4.4.3] on linux-armv7l
Type "help", "copyright", "credits" or "license" for more information.
>>> print ";)"
;)
>>> exit()
root@C1905:/ #

hope this helps someone

0

Source: https://habr.com/ru/post/1599100/


All Articles