linzhao789 发表于 2020-11-20 11:09

迅为-iMX6ULL开发板-Python移植-编译1

本章节介绍 Python 如何移植到 IMX6ULL 开发板上,并有几个简单的测试例程。本章节使用的资料已经放到了开发板网盘资料中,路径为:11_Linux 系统开发进阶\92_章节_Python 移植使用资料。
92.1源码包
和文档在一起的源码包有:“python-2.7.3 源码和补丁.zip”---python 压缩包和补丁文件;
“install_python.tar”---编译好的 sqlite 库文件;
“sqlite-autoconf-3240000.tar.gz”---sqlite 的源码文件;
“测试程序”---python 测试例程。
到 Python 官网下载源码包 2.7.3,地址 http://www.eechina.com/data/attachment/forum/202011/20/103956ofqqdvfn0x00xq0z.png 或者使用压缩包中提供的源码
http://www.eechina.com/data/attachment/forum/202011/20/103312s2ab25d5zdtokbpf.jpg
通过 ssh 将 Python-2.7.3.tar.bz2 和补丁 Python-2.7.3-xcompile.patch 拷贝到ubuntu 系统的 home/miniLinux 目录下,使用命令 tar -vxf Python-2.7.3.tar.bz2 解压源码压缩包得到目录 Python-2.7.3。
http://www.eechina.com/data/attachment/forum/202011/20/103312m20sd2fi4flfls2g.jpg
92.2编译
92.2.1编译 host版解释器
编译 Python 的嵌入式版需要解释器解析 setup.py 从而编译 Python 的模块,因此需要先编译出 HOST 的解释器 。
进入解压出来的”Python-2.7.3”,目录,执行命令“./configure”运行配置文件。
执行完后生成 Makefile 文件,如图 92.2.1.1:
http://www.eechina.com/data/attachment/forum/202011/20/103312v361jdppspsawzrr.jpg
执行命令“make python Parser/pgen”,编译 PC 版 python Parser/pgen ,成功后如图 92.2.1.2:
http://www.eechina.com/data/attachment/forum/202011/20/103312g8q6bjj6jjc1yqb1.jpg
执行命令“mv python hostpython”将生成的 PC 版移动至 hostpython ,
执行命令“mv Parser/pgen Parser/hostpgen”将生成的 PC 版解释器移动至 Parser/hostpgen 。
http://www.eechina.com/data/attachment/forum/202011/20/103312nbybp04ozonr84ob.jpg
执行命令“make distclean”清除不必要的文件。
http://www.eechina.com/data/attachment/forum/202011/20/103312ay0w21avp4yvv1wy.jpg 92.2.2 arm补丁
交叉编译的补丁我们放到 python 目录下,执行命令 patch -p1 http://www.eechina.com/data/attachment/forum/202011/20/103312vc99bxqbcsqtttts.jpg
92.2.3交叉编译配置
在“/home/ubuntu/python/Python-2.7.3”目录下执行以下命令进行设置 :
设置交叉编辑器 CC=arm-none-linux-gnueabi-gcc
设置 C++交叉编译器 CXX=arm-none-linux-gnueabi-g++
设置 AR AR=arm-none-linux-gnueabi-ar
设置 RANLIB RANLIB=arm-none-linux-gnueabi-ranlib
http://www.eechina.com/data/attachment/forum/202011/20/103312ky9ifgiazmlihmuu.jpg
92.2.4编译和安装测试
将压缩包中提供的编译好的 sqlite3 库“install_python.tar”通过 ssh 拷贝到 /home/ubuntu/python 下然后解压,得到“install_python”。
用户也可以自己编译 sqlite3 库,本文第四小节介绍库的编译。
http://www.eechina.com/data/attachment/forum/202011/20/103312rll9zzla97seogd0.jpg
进入 Python-2.7.3,执行命令“vim setup.py”修改 setup.py ,找到 1044 行将 paths 改为 install_python所在路径,如图 92.2.4.2 所示。
http://www.eechina.com/data/attachment/forum/202011/20/103312mvvi2qgqqa8avav6.jpg
定位到 1099 行,修改路径如图 92.2.4.3 所示。
http://www.eechina.com/data/attachment/forum/202011/20/103509skzful5skiosxkxl.jpg
执行命令“./configure --host=arm-none-linux-gnueabi --prefix=/python ”生成符合交叉编译器的 Makefile,成功后如图 92.2.4.4。
http://www.eechina.com/data/attachment/forum/202011/20/103509pvgty0tc8tpg10sq.jpg
执行 make 命令进行编译“make HOSTPYTHON=./hostpythonHOSTPGEN=./Parser/hostpgen BLDSHARED="arm-none-linux-gnueabi-gcc -shared"
CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes ”此时会提示缺失模块,忽略
http://www.eechina.com/data/attachment/forum/202011/20/103509kvrv8bl8a2ffyzf0.jpg
成功后如图 92.2.4.6:
http://www.eechina.com/data/attachment/forum/202011/20/103509gpzsm0ouu00opjkk.jpg
执行以下命令安装到指定文件夹“make install HOSTPYTHON=./hostpython
BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-nonelinux-gnueabi-
CROSS_COMPILE_TARGET=yes prefix=/home/ubuntu/python/Python-2.7.3/_install”。
其中 prefix=/home/ubuntu/python/Python-2.7.3/_install 是指定的安装目录,用户根据实际情况更改。
http://www.eechina.com/data/attachment/forum/202011/20/103509g44hnahn4az5ysen.jpg
成功后如图 92.2.4.8:
http://www.eechina.com/data/attachment/forum/202011/20/103509f5zgtyn8iot4ytaa.jpg
使用命令“ls _install”查看结果:
http://www.eechina.com/data/attachment/forum/202011/20/103509jzbx5rek1m5kgom5.jpg
拷贝 sqlite3 库文件到“/Python-2.7.3/_install/lib/”下 :
cp install_python/lib/libsqlite3* Python-2.7.3/_install/lib/
http://www.eechina.com/data/attachment/forum/202011/20/103509ar5bjhh0hllvdwvj.jpg
将_install 目录整个打包,拷贝到开发板上的“/data”目录下,然后解压,笔者使用的是NFS 挂载的根文件系统 ,用户也可以通过 NFS 挂载目录或 U 盘拷贝过去。
http://www.eechina.com/data/attachment/forum/202011/20/103509yn6nnmxgppvnnqgy.jpg
进入_install 目录,使用命令以下命令设置环境变量:“export export LD_LIBRARY_PATH=/data/_install/lib{:shy:}LD_LIBRARY_PATH”
http://www.eechina.com/data/attachment/forum/202011/20/103509d4ellbxl70mhxhhw.jpg
http://www.eechina.com/data/attachment/forum/202011/20/103913tf952197g5kg5z53.jpg
http://www.eechina.com/data/attachment/forum/202011/20/104035t9nxq8st568can86.jpg

charlottegerisi 发表于 2021-6-16 10:12

感谢
页: [1]
查看完整版本: 迅为-iMX6ULL开发板-Python移植-编译1