Cross-compiling python to embedded arm (support import sqlite3,datetime, etc.)-----compiling python for Embedded Linux

Source: Internet
Author: User

This is the graduation brother's Virgo blog, I hope you do not spray!!!

Due to the needs of the laboratory project, graduating brother began to study Python at 9 o ' Night (2014/11/05). Oneself a bit obsessive-compulsive disorder, install what software all request new, so give oneself windows to install a Python3.3 (also bury a thunder for oneself). Before I installed Python-2.7.3 on a Linux machine, I didn't think much of it, thinking that the Python Premium version was backwards compatible. So began to beg the graduation brother on the road of Thunder ... raw_input (), ", Socket communication ... In short, different versions of incompatible AH!!!

To the point, the Graduate (hereinafter referred to as the graduation) of the laboratory is a xxxxxx (here omitted 1MBytes word). In short, it is the "cool" laboratory under the Chinese characteristic university.

Previous seniors/Sisters used Linux C as the development language for Arm-linux embedded systems (mainly for network communication). However, after I came to the laboratory, I found a lot of people are troubled waters, C language level simply ...

In order not to generation pit generation, so I would like to translate the development language into Python, but also let the later learning younger sisters can quickly, and really master a technology bar. (Don't dabbler like C!!!!) )

  

So...... Here's the problem!

I've heard of Linux running Python (nonsense, who hasn't heard it), so what about Python porting to arm?

  

Fortunately, the graduation of arm toss Kung fu is OK, I took 2 seconds to think:

1: Sure to go to the official source (the amount, anyway, I should not write it out)

2: Sure to use Cross compiler (well, friends who would like to see my blog should know what a cross compiler is)

3: Need to compile yourself. Can you please stop nagging?

The dry goods come!!!

  Well, through the above part of the background to pave the way to graduate has basically know how to edit the blog park!

Pre-transplant preparation work:

1,linux operating System (for graduation is Ubuntu 12.04)

2,linux operating system with cross compiler (this compiler needs to match your embedded device), Graduation Cross compiler is:ARM-XILINX-LINUX-GNUEABI-GCC

3,python source package, go to the official website FTP

Appendix: Documents for graduation contribution to everyone

OK, here we go! Seeking graduation with Python-2.7.3 as an example

1/home/liu# Tar jxvf python-2.7.3.tar.bz2

2/home/liu# CD python-2.7.3/

Run the configuration file, generate the necessary makefile and other files

3/home/liu/python-2.7.3#./configure

Compiling the PC version of Python Parser/pgen

4/home/liu/python-2.7.3# make Python Parser/pgen

Move the generated PC version to Hostpython

5/home/liu/python-2.7.3# MV Python Hostpython

Move the generated version of the PC interpreter to Parser/hostpgen

6/home/liu/python-2.7.3# MV Parser/pgen Parser/hostpgen

Clear unnecessary files

7 Make Distclean

The following sections involve cross-compiling python

First put the patch on:

8/home/liu/python-2.7.3# Patch-p1 < <your patch path>/python-2.7.3-xcompile.patch

Setting the necessary environment variables

Setting up the Cross compiler

9/home/liu/python-2.7.3# CC=ARM-XILINX-LINUX-GNUEABI-GCC

Set up the C + + cross compiler

10/home/liu/python-2.7.3# cxx=arm-xilinx-linux-gnueabi-g++

Set AR

11/home/liu/python-2.7.3# Ar=arm-xilinx-linux-gnueabi-ar

Set Ranlib

12/home/liu/python-2.7.3# Ranlib=arm-xilinx-linux-gnueabi-ranlib

Generate a makefile that conforms to the cross compiler

13/home/liu/python-2.7.3#./configure--host=arm-xilinx-linux-gnueabi--prefix=/python

Make

14/home/liu/python-2.7.3# make Hostpython=./hostpython Hostpgen=./parser/hostpgen bldshared= " Arm-xilinx-linux-gnueabi-gcc-shared "Cross_compile=arm-xilinx-linux-gnueabi-cross_compile_target=yes

This step will find that many modules are missing, and these missing modules will cause the import Sqlite3,ssl to fail after running Python. (no matter what, we'll teach you later, add this module)

  

Make install to the specified file

15/home/liu/python-2.7.3# make install Hostpython=./hostpython bldshared= "arm-xilinx-linux-gnueabi-gcc-shared" Cross_compile=arm-xilinx-linux-gnueabi-cross_compile_target=yes Prefix=/home/liu/python-2.7.3/_install

At this point, files that can be executed on arm are generated in the/home/liu/python-2.7.3/_install

Check out LS _install

_install ls, in the bin directory, there is an arm executable python binary file

  

Test:

The _install folder is now copied to arm's file system, where it is freely available

CD <your path>/_install/bin (Note: This is done on arm)

./python

OK, the transplant is successful!

Write a few small code, test it!

  

Unlike many online versions, you cannot import datatime, time, sockets, or anything.

In addition: The above part, is to learn from the foreign two friends do
1:http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html

2:http://www.cnx-software.com/2011/02/04/cross-compiling-python-for-mips-and-arm-platforms/

   But there is no support for SQLite, why? Let 's guess, I'll go to dinner first. Continue to write tomorrow, has successfully supported the Sqlite3, but also for graduation is absolutely original!!!

Cross-compiling python to embedded arm (support import sqlite3,datetime, etc.)-----compiling python for Embedded Linux

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.