我有一个 Android 5.1 CM12(root、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
这个错误告诉我什么!以及如何解决?
最佳答案
我玩了一段时间,终于搞定了。 我的脚本(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:/ #
希望对大家有帮助
关于android - 在 Android 终端中运行 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31564123/