Porting Python Notes

Source: Internet
Author: User

This article is original, reprint please specify: http://www.cnblogs.com/tolimit/

compilation environment:ubuntu-14.04.1

compiler:gcc, Arm-hisiv200-linux-gnueabi

python version:2.7.3

The process is relatively simple and consists of three steps:

    1. Compiling the X86 version of Python
    2. Cross-compile patch for Python source
    3. Cross-compiling Python

Compiling the X86 version of Python

Enter the python source directory and execute:

./configure 

Compiling Python and Parser/pgen

 make Python Parser/pgen

Back up the X86 version of the Python executable to Python_for_build

mv python python_for_build 

The X86 version of the Pgen executable is equipped with the Pgen_for_build

mv Parser/pgen parser/pgen_for_build 

Clean up the compiled project files, this step is for the subsequent cross-compilation to prepare

 make Distclean

The most important thing about the whole step is to save both the Python and Pgen executables, since these two files will be used when you cross-compile python.

Cross-compile patch for Python source

My Python version is 2.7.3, so the patch also needs to hit the corresponding version, different versions of the patch as follows:

    • Python-2.6.6-xcompile.patch
    • Python-2.7.2-xcompile.patch
    • Python-2.7.3-xcompile.patch
    • Python-3.1.1-xcompile.patch
    • Python-3.1.2-xcompile.patch
    • Python-3.1.3-xcompile.patch
    • Python-3.2.2-xcompile.patch

  

Enter the python source directory and execute

Patch -P1 < python-2.7. 3-xcompile. Patch

This shows that the patch is successful

Cross-compiling Python

Configuration

    • CC for the specified c cross compiler, mine is ARM-HISIV200-LINUX-GNUEABI-GCC
    • Cxx for the specified C + + cross compiler, mine is arm-hisiv200-linux-gnueabi-g++
    • AR for AR tool, mine is Arm-hisiv200-linux-gnueabi-ar
    • Ranlib is the Ranlib tool, mine is arm-hisiv200-linux-gnueabi-ranlib.
    • Host is the target, I'm setting the Arm-hisiv200-linux-gnueabi
    • Build to compile the environment host, mine is X86-linux-gnu
    • Prefix for mounting position

My entire configuration command is as follows:

cc=arm-hisiv200-linux-gnueabi-gcc cxx=arm-hisiv200-linux-gnueabi-g++ ar=arm-hisiv200-linux-gnueabi-  Ar ranlib=arm-hisiv200-linux-gnueabi-ranlib./configure--host=arm-hisiv200-linux-gnueabi--build= X86-linux-gnu--prefix=/home/shanlink/cross_compile/python-arm/

Here you remember to change the corresponding parameters on your machine

Compile

    • Hostpython Specify the X86 version of the Python file that we compiled earlier
    • Hostpgen Specify the X86 version of the Pgen file that we compiled earlier

My entire compile command is as follows (different compilers need to modify the corresponding Arm-hisiv200-linux-gnueabi location):

 Make Hostpython=./python_for_build hostpgen=./parser/pgen_for_build bldshared="  arm-hisiv200-linux-gnueabi-gcc-shared" cross_compile=arm-hisiv200-linux-gnueabi-cross_compile_ Target=yes Hostarch=arm-hisiv200-linux-gnueabi Buildarch=x86-linux-gnu

Installation

compile with the following details:

 Make Install Hostpython=./python_for_build bldshared="arm-hisiv200-linux-gnueabi-gcc-shared" Cross _compile=arm-hisiv200-linux-gnueabi-cross_compile_target=yes Prefix=/home/shanlink/cross_compile/python-arm

Finally, there are newly generated files and folders in the directory specified by prefix, and the main folder is/bin,/include,/lib,/share. Copy them all to the/usr directory of the target machine. Finally, execute a command on the target machine to check if the Python environment is complete.

Python/usr/lib/python2. 7/test/test___all___.py

Error

I did not encounter an error when I migrated to the above method, but I encountered an error when I migrated in other ways, and here is a note.

    • The following error has been encountered at compile time
#error "This platform ' s pyconfig.h needs to define Py_format_long_long"

Edit the Pyconfig.h file, locate #undef Py_format_long_long, add a line # define Py_format_long_long "LL"

    • The following error was encountered while running test on the target machine
' Import Site '  for  last):  "test.py"2 in < module>    Import osimporterror:no module named OS

During the execution of the process found that all of the Python Py/pyc library files are not found, is due to pythonhome the path specified by the problem, and pythonhome the file schema has a problem, it must be: ${pythonhome}/lib/python2.7. Generally we copy the compiled folder (bin,lib,include,share) directly to USR, there is no problem (the Python library will be put into the/usr/lib/python2.7 inside)

Porting Python Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.