由于工程需要,需要向AM3352(周立功Iot9608I)主控制板上面移植Python。 首先下载python源代码以及补丁文件:https://pan.baidu.com/s/1dFFZeX7 然后开始编译,因为软件系统跟之前几篇帖子使用同一个环境,都是周立功提供的linux编译工具。下面直接开始:

./configure 
make python Parser/pgen  
mv python python_for_build  
mv Parser/pgen Parser/pgen_for_build  
make distclean  
patch -p1 < ../Python-2.7.3-xcompile.patch  
CC=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc 

CXX=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-g++ 

AR=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ar RANLIB=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ranlib 

./configure --host=/opt/arm-2011.03/bin/arm-none-linux-gnueabi --build=x86-linux-gnu --prefix=/home/qinfei/python-arm/
make HOSTPYTHON=./python_for_build HOSTPGEN=./Parser/pgen_for_build BLDSHARED="/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=/opt/arm-2011.03/bin/arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=/opt/arm-2011.03/bin/arm-none-linux-gnueabi  BUILDARCH=x86-linux-gnu  
make install HOSTPYTHON=./python_for_build BLDSHARED="/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=/opt/arm-2011.03/bin/arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=/home/qinfei/python-arm  

之后把/home/qinfei/python-arm目录内的文件拷贝到嵌入式设备上面,由于我是用的U盘拷贝之前格式化为Fat32文件系统,不支持符号链接,会报如下错误:

cp: cannot create symbolic link to fat format of usb: Operation not permitted  

我们使用可以使用"cp -rL source dest"把所有符号链接替换成实实在在的文件即可,或者格式化成其他文件系统。

然后拷贝到嵌入式设备中以后,还需要更改环境变量,一不小心,把export PATH=/My /Python /Dir 写在了原来的export PATH之后,问题大了,环境变量全部丢失了,幸亏之前查看过环境变量,还在控制台可见窗口里面,复制一下再次粘贴到命令行里面:

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/bin  

在后面添加python bin路径:

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/bin:/opt/python-arm/bin  

然后source ~/.bash_profile即可。

至此python移植完成,安安稳稳运行在AM3352 Linux系统中。