在Android终端中运行Python

时间:2015-07-22 13:09:27

标签: android shell python-2.7

我有一个Android 5.1 CM12(rooted,supersu,busybox)并尝试通过Android终端访问Python For Android(PythonForAndroid_r5.apk)。

我已经遵循了这个教程: http://lifepluslinux.blogspot.de/2015/01/installing-python-on-android-50.html

这是我使用的脚本(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和sh位于system / bin /

但是当我执行这些脚本时,我得到:

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

什么告诉我这个错误!以及如何解决它?

1 个答案:

答案 0 :(得分:0)

我已经玩了一段时间,最后我开始工作了。 我的脚本(python2位于system / bin中):

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 "$@"

在Android终端上:

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

现在可以在Android 5.1终端中包含Python2.7了!

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:/ #

希望它可以帮到某人