How to Port Python on iMX6Q Development Board

This article is based on Forlinx OKMX6Q/ OKMX6DL-C development board. This series uses i.MX6Q/DL processors. The system for demonstrating Python porting is linux3.0.35. Other platforms can refer it, but there will be differences among different platforms, you may modify according to the actual circumstance.

iMX6Q/DL Python Porting

Attention: Required toolkits are in Python porting/toolkits

Generated Portable Python is in Python porting/output

Process 1: Compile Python

Preparatory work

The following files are needed in the following compilation







Prepare the Environment

cd /root

mkdir mx6q-python2.7/ && cd mx6q-python2.7

mkdir –p {python2_7_13_for_x86_64,python2_7_13_for_arm,INSTALL,sqlite3,misc,output/sources}

Copy the package prepared above to mx6q-python2.7, and move zlib-1.2.3.tar.gz and to directory: misc. Or directly copy the file mx6q-python2.7 in the provided package to directory: /root .

iMX6Q/DL Python Porting

View the cross-compiler toolchain

View the current cross-compiler toolchain. If inconsistent, replace with the compiler below.

The current cross-compiler toolchain is arm-none-linux-gnueabi-, which can be viewed by the following command.

find / -name arm-*-gcc

If the cross-compiler toolchain is inconsistent, replace with the compiler below

How to Port Python on iMX6Q Development Board

Compile and install

Compile and install sqlite3

Compile and install sqlite3, Python needs sqlite3 support.

cd /root/mx6q-python2.7/

tar xvf sqlite-autoconf-3200100.tar.gz

cd sqlite-autoconf-3200100

./configure --host=arm-none-linux-gnueabi --prefix=$PWD/../sqlite3

make -j8 && make install

Compile openssl and zlib

compile zlib

cd /root/mx6q-python2.7/misc/

tar xvf zlib-1.2.3.tar.gz

cd zlib-1.2.3

mkdir arm_install

./configure --prefix=./arm_install/

sed -i 's/gcc/arm-none-linux-gnueabi-gcc/g' Makefile

sed -i 's/AR=ar/AR=arm-none-linux-gnueabi-ar/g' Makefile


make install

Compile openssl

cd /root/mx6q-python2.7/misc/


cd openssl-OpenSSL_1_0_1b

mkdir arm_install

./Configure --prefix=`pwd`/arm_install/ os/compiler:arm-none-linux-gnueabi-gcc

modify the CC variable in Makefile to CC= $(CROSS_COMPILE)gcc


make install

Package the compiled installation package, which will be used when porting to the development board

cd arm_install

tar jcvf openssl-OpenSSL_1_0_1b.tar.bz2 *

cp openssl-OpenSSL_1_0_1b.tar.bz2 /root/mx6q-python2.7/output/sources

| Compile python2.7

Compile python2.7 for x86

cd /root/mx6q-python2.7/

tar xvf Python-2.7.13.tgz

cd python2_7_13_for_x86_64/

sed -i 's/self.extensions.remove(ext)/print(' ../Python-2.7.13/

../Python-2.7.13/configure --prefix=`pwd`

make -j8 && make install

Compile python2.7 for arm


cd ..

tar xvf Python-2.7.13-xcompile.patch.tar.gz -C Python-2.7.13

cd Python-2.7.13/

patch -p1 < Python-2.7.13-xcompile.patch

Modify the configuration of module connection

vim Modules/Setup.dist, uncomment the following configuration

zlib zlibmodule.c -I$(prefix)/include -L$(prefix)/lib -lz

_ssl _ssl.c \

-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

-L$(SSL)/lib -lssl -lcrypto

Compile python2.7 for arm


cd ../python2_7_13_for_arm/

Copy bksh to /root/mx6q-python2.7/

cp ../bksh/py2* . can directly run the script

Or enter the command below.

../Python-2.7.13/configure --prefix=`pwd` \

--host=arm-none-linux-gnueabi \

--build=x86_64-linux-gnu \

--enable-ipv6 \

--enable-static \

ac_cv_file__dev_ptmx="yes" \

ac_cv_file__dev_ptc="no" \

LDFLAGS="-L$PWD/../sqlite3/lib -L$PWD/lib" \

CPPFLAGS="-I$PWD/../sqlite3/include -I$PWD/include -I$PWD/include/openssl"

Before the next step: execute make, install zlib and openssl. And copy each respective include and lib to python2_7_13_for_arm. Or directly run to automatically copy the include and lib of the zlib and openssl under misc to the current directory.


cd /root/mx6q-python2.7/python2_7_13_for_arm/

Run or run the command below.

make install HOSTPYTHON=../python2_7_13_for_x86_64/python \

BLDSHARED="arm-none-linux-gnueabi-gcc -shared" \

CROSS_COMPILE=arm-none-linux-gnueabi- \




Run or run the command below.

make install HOSTPYTHON=../python2_7_13_for_x86_64/python \

BLDSHARED="arm-none-linux-gnueabi-gcc -shared" \

CROSS_COMPILE=arm-none-linux-gnueabi- \




cd ../INSTALL/

tar jcvf python2.7-for-arm.tar.bz2 *

cp python2.7-for-arm.tar.bz2 ../output/sources/

| ntpdate network time synchronization tool

cross compile

cd /root/mx6q-python2.7

tar xvf ntp-4.2.8p10.tar.gz

cd ntp-4.2.8p10/

mkdir arm_install

./configure --prefix=$PWD/arm_install --host=arm-none-linux-gnueabi --enable-static --with-yielding-select=yes

make && make install


If do not need help documents, delete the directory /share in arm_install, to save space

cd arm_install

rm share -rf

tar jcvf ntp-4.2.8.p10.tar.bz2 *

cp ntp-4.2.8.p10.tar.bz2 ../../output/

| output directory

Copy setuptools to output directory

cd /root/mx6q-python2.7/

cp setuptools-0.6c11-py2.7.egg output/sources/

The final directory format is as follows:

├── ntp-4.2.8.p10.tar.bz2

└── sources


├── python2.7-for-arm.tar.bz2

└── setuptools-0.6c11-py2.7.egg

Now, the python compilation is complete. Please refer "python2.7 direct use manual" for the steps of porting to development board.

Process 2: Configure Python on development board

Copy the output folder generated above to iMX6Q development board

1. Unzip the package to development board

tar xvf python2.7-arm.tar.bz2 -C /

tar xvf openssl-OpenSSL_1_0_1b.tar.bz2 -C /

cp setuptools-0.6c11-py2.7.egg /

cp ntp-4.2.8p10-arm-no-share.tar.gz /

2. Modify the configuration

Modify /lib/pkgconfig/python2.pc as follows.





Modify the first line of vi /bin/python2.7-config as follows.


Add the following configuration to /etc/profile. After successful modification, it is source /etc/profile


export PYTHONPATH=$PYTHONHOME:$PYTHONHOME/lib/python2.7:$PYTHONHOME/lib:$PYTHONHOME/lib/python2.7/site-packages


3. Go to the folder easy_install and install easy_install.

Enter /bin/bash setuptools-0.6c11-py2.7.egg to install easy_install.

Modify vi /etc/profile,

Add alias easy_install='easy_install -i'.

Save and exit to facilitate installation and management later, source /etc/profile to make the configuration effective

4. Cancel SSL global verification and verify easy_install, modify vi /bin/easy_install and add the following configuration.

import SSL

ssl._create_default_https_context = ssl._create_unverified_context

5. Configure network

Refer to other configuration application notes for methods of configuring network.

6. Installing ntp, enter ntp folder.

tar xvf ntp-4.2.8p10-arm-no-share.tar.gz -C /


Note: There may be errors here due to the ntp URL problem. You can directly search for the error message and solve it.

7. Install pip

easy_install pip After the installation is successful, pip -V to view the current installed version.

8. pip install module test

pip install requests

pip list to view the installed modules.

9. Import module test, enter python2.7 to enter python2.7 shell. Enter import requests, no error output. Type exit() to exit python shell.