android手机搭建python运行环境

1. 下载安装SL4A

https://code.google.com/p/android-scripting

2. 下载安装python-for-android

https://code.google.com/p/python-for-android/downloads/detail?name=Python3ForAndroid_r6.apk

3.  配置python环境

  • 重新挂载/system分区,使其可读写
mount -r -w -o remount -t rootfs /system
  • 创建/system/python目录和/system/python/lib目录,并将python相关的文件复制到/system/python下和/system/python/lib下
mkdir /system/python
mkdir /system/python/lib
cp -R /data/data/com.googlecode.pythonforandroid/files/python/* /system/python
cp -R /sdcard/com.googlecode.pythonforandroid/extras/python/* /system/python/lib/
cp /system/python/bin/* /system/bin
  • 添加以下内容到到/system/etc/bash/bashrc(如果没有该文件则创建该文件)
export PYTHONHOME="/system/python"
export PYTHONPATH=.:$PYTHONHOME:$PYTHONHOME/libs:$PYTHONHOME/lib:$PYTHONHOME/lib/site-packages:$PYTHONHOME/lib/python2.6/lib-dynload
export PATH=$PYTHONHOME:$PYTHONPATH:$PATH
export LD_LIBRARY_PATH=.:$PYTHONHOME/lib:$LD_LIBRARY_PATH


4.  在shell中运行python
  • 在手机上安装终端模块器,用手机助手安装就可以了
  • 安装BusyBox,同样用手机助手安装就可以了
  • 安装完之后,打开终端模拟器,进入首选项->初始命令,输入以下命令:
. /system/etc/bash/bashrc
  • 重新启动终端模拟器,这样就可以在终端模拟器中运行python啦

你可能感兴趣的:(python,android)