zynq平台移植python3.10.5

2023-02-28 12:53:38 浏览数 (1)

  • 主机:ubuntu16.04
  • 下载python3.10.5源码(https://www.python.org/downloads/release/python-3105/)

1. x86下安装python3.10.5

在交叉编译python3之前需要在ubuntu主机上安装对应的x86版本,因为交叉编译时需要用到python解释器。ubuntu16.04下安装python3.10.5

1.1 安装ctypes模块需要的库文件libffi

  • 下载libffi-3.4.2源码(https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz)
  • 编译
代码语言:javascript复制
tar zxvf libffi-3.4.2.tar.gz
cd libffi-3.4.2
./configure --disable-docs
make
make install

1.2 编译安装python3.10.5

代码语言:javascript复制
tar xvf Python-3.10.5.tar
cd Python-3.10.5
export LD_LIBRARY_PATH=/usr/local/lib
export LD_RUN_PATH=/usr/local/lib
./configure --enable-optimizations LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I /usr/local/include"
make
make install

2. 交叉编译python3.10.5

交叉编译ctypes模块需要的库文件libffi

代码语言:javascript复制
tar zxvf libffi-3.4.2.tar.gz
./configure --prefix=/opt/Xilinx2018_zynq/zynq_Python/Modules/libffi --build=x86_64-linux-gnu --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf CC=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc CXX=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-g   AR=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ar RANLIB=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ranlib --disable-docs
make
make install

2.1 交叉编译python3.10.5

代码语言:javascript复制
tar xvf Python-3.10.5.tar
cd Python-3.10.5
export LD_LIBRARY_PATH=/opt/Xilinx2018_zynq/zynq_Python/Modules/libffi/lib
export LD_RUN_PATH=/opt/Xilinx2018_zynq/zynq_Python/Modules/libffi/lib
./configure --prefix=/opt/Xilinx2018_zynq/zynq_Python/zynq_Python3.10.5 --build=x86_64-linux-gnu --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf CC=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc CXX=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-g   AR=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ar RANLIB=/opt/Xilinx/SDK/2018.3/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ranlib ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=yes --disable-ipv6 --with-ensurepip=yes --enable-optimizations LDFLAGS="-L/opt/Xilinx2018_zynq/zynq_Python/Modules/libffi/lib" CPPFLAGS="-I/opt/Xilinx2018_zynq/zynq_Python/Modules/libffi/lib"
make 
make install

2.2 打包python文件到目标板

  • tar cvf zynq_Python3.10.5.tar zynq_Python3.10.5
  • cp libffi.so.8.1.0 至目标板/usr/lib/
  • cd /usr/lib && ln -s libffi.so.8.1.0 libffi.so && libffi.so.8;libffi库是ctypes模块所需要的
  • tar zynq_Python3.10.5.tar至相应的目录,在/usr/bin/目录下建立python3解释器的软连接:cd /usr/bin && ln -s /app/zynq_Python3.10.5/bin/python3.10 python3

至此,python3环境已移植到目标板,运行python3命令来验证

0 人点赞