Giter VIP home page Giter VIP logo

python3's Introduction

Python for android

This project is based on the version 3.5.1 of python. I have made some changes to the source code The specific steps for compile are as follows:

1.Preparation

  • cross compiler toolchain was exported by ndk.

  • ubuntu15.10 x64.

  • python library need lots of dynamic libraries. And these libraries under folder of Libraries. Before comile, put the header and library to path/to/toolchain/sysroot/usr/include and path/to/toolchain/sysroot/usr/lib.

2.Compile

We shoud compile the source code under pc and android, because we need the executables pgen and _freeze_importlib which compile under PC. Unfortunately, i modify some source code, so this project could not be compiled for PC.

  • build pc.

    get the source code from https://www.python.org/downloads/release/python-351/, then build

    ./configure && make

    Or use the prebuilt executables, pgen and _freeze_importlib.

  • cross compile

    ./configure  --build=x86_64-linux-gnu --host=arm-linux-androideabi --disable-ipv6 CONFIG_SITE=config.site --prefix=/system/
  • Modify the Setup file under folder Modules to specify the modules should be compiled.

  • Then you'll get errors,According to the errors, you may need to copy the executable pgen or _freeze_importlib which compile under PC to the right folder , and they under folder Parser or Programs. Do not forget to modifiy the time of each file.

    touch ./Parser/pgen 
    #Or
    touch ./Programs/_freeze_importlib

    The continue compiling.

  • make install DESTDIR=/path/to/you/like

####3.Compiled

  • Once compiled successfully,you can reduce the volume of executable use strip command. Like this:

    arm-linux-androideabi-strip python3.5
  • Delete the static library if you don't need it.

  • You can compress the standard library which under the directory of lib/python3.5 (use zip), and then put the compressed zip(python35.zip) file in the right place(may be under /system/lib/python3.5/). Or just put the zip to sdcard and export the PYTHONPATH when used. If you doesn't compress the library, put the library folder under /system/lib/. You shouldn't put the uncompressed library to sdcard because android doesn't support load shared library from sdcard. But you can push the compressed library to sdcard.

####4.Test

  • if you use the library was compressed, you may need to set PYTHONPATH for python.

    path

  • supported modules

    modules

####5.Attention

This could use in adb shell, but not in an android app, I still working on it!

python3's People

Contributors

jianglei12138 avatar viperfx avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.