当前位置: 首页 > news >正文

交叉编译python3.8版本

下载源码

https://www.python.org/downloads/source/。选择Python-3.8.20的xz版本。

交叉编译

配置交叉编译工具链环境,由于使用的是模组厂商提供的yocto编译链,aarch64-zxic-linux-gcc,里面已经包含了很多库和头文件,所以不需要额外下载单独编译。

最终配置参数命令:

mkdir local_build ./configure --host=arm-linux --build=x86_64-linux-gnu --prefix=/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/

问题1:提示交叉编译的文件不能运行,需要同时设置host和build参数

[wangyb@wangyb-VirtualBox:Python-3.8.20]$ ./configure configure: loading site script /home/wangyb/sda3/zm9300c-V2XR240060/toolchain/site-config-aarch64-zxic-linux checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.8... python3.8 checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... "linux" checking for gcc... aarch64-zxic-linux-gcc -mcpu=cortex-a53+crc -fstack-protector-all -pie -fPIE -Wformat -Wformat-security -Werror=format-security -fstack-protector-all -pie -fPIE -Wformat -Wformat-security -Werror=format-security --sysroot=/home/wangyb/sda3/zm9300c-V2XR240060/toolchain/sysroots/aarch64-zxic-linux checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... configure: error: in `/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details configure:4045: checking whether we are cross compiling configure:4053: aarch64-zxic-linux-gcc --sysroot=/home/wangyb/sda3/zm9300c-V2XR240060/toolchain/sysroots/aarch64-zxic-linux -o conftest -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-all -Wl,-z,relro,-z,now -fstack-protector-all -Wl,-z,relro,-z,now conftest.c >&5 configure:4057: $? = 0 configure:4064: ./conftest ./configure: line 4066: ./conftest: cannot execute binary file: Exec format error configure:4068: $? = 126 configure:4075: error: in `/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20': configure:4077: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details

问题2:提示/dev/ptmx... not set,查看是存在/dev/ptmx文件,所以需要加上yes,删除目录重新解压重新配置解决。

./configure --host=arm-linux --build=x86_64-linux-gnu --prefix=/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/ --disable-ipv6 ac_cv_file__dev_ptmx=yes

问题3:提示/dev/ptc... not set,查看没有/dev/ptc文件,所以需要设置no

./configure --host=arm-linux --build=x86_64-linux-gnu --prefix=/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/ --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no

make编译成功:

[wangyb@wangyb-VirtualBox:Python-3.8.20]$ file python python: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=a750cfafb04ee7d9d390d4b2491ce932e8bfa724, for GNU/Linux 3.14.0, not stripped [wangyb@wangyb-VirtualBox:Python-3.8.20]$ ls python -lh -rwxrwxr-x 1 wangyb wangyb 17M 2月 25 14:25 python [wangyb@wangyb-VirtualBox:Python-3.8.20]$ aarch64-zxic-linux-strip python [wangyb@wangyb-VirtualBox:Python-3.8.20]$ ls python -lh -rwxrwxr-x 1 wangyb wangyb 3.3M 2月 25 14:30 python linux_genvict:root# ./python-strip -V Python 3.8.20

make install进行依赖库和文件安装到目录local_build,否则单独的python不能成功运行

linux_genvict:root# ./python Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = './python-strip' isolated = 0 environment = 1 user site = 1 import site = 1 sys._base_executable = '/root/python-strip' sys.base_prefix = '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build' sys.base_exec_prefix = '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build' sys.executable = '/root/python-strip' sys.prefix = '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build' sys.exec_prefix = '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build' sys.path = [ '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/lib/python38.zip', '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/lib/python3.8', '/home/wangyb/sda3/zm9300-tools/tools/Python-3.8.20/local_build/lib/lib-dynload', ] Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings' Current thread 0x0000007fbd09c600 (most recent call first): <no Python frame> linux_genvict:root#

安装运行

local_build目录200MB,压缩后拷贝到板子环境中,解压到emmc存储中进行运行测试。

[wangyb@wangyb-VirtualBox:Python-3.8.20]$ du -sm local_build/ 200 local_build/ linux_genvict:root# /mnt/emmc1/local_build/bin/python3 -V Python 3.8.20 linux_genvict:root# /mnt/emmc1/local_build/bin/python3 Type "help", "copyright", "credits" or "license" for more information. >>> print("hello") hello >>>

如果需要放在发布包中需要压缩后存放app目录。

http://www.jsqmd.com/news/412982/

相关文章:

  • 工时日志在项目进度管理中扮演着怎样的角色?
  • 2026年知名的喷涂哪家专业工厂直供推荐 - 品牌宣传支持者
  • 北京宠物寄养学校哪家条件和服务比较好?北京宠物寄养宾馆酒店名单 - 品牌2025
  • 2026年通州狗狗训练哪家好?通州狗狗训练哪家条件和服务比较好 - 品牌2025
  • IBM-IT蓝图与实施规划
  • 微软偷偷放出一个量化利器,GitHub 狂揽3.7万Star!
  • 通州宠物寄养哪家好?2026年专业正规通州宠物寄养分享 - 品牌2025
  • 20年前,因冯巩一句话离开中国,洋人相声演员大山,如今怎样了?
  • 孙俪儿子帅到认不出!年仅14岁身高1米7,梦想打CBA职业联赛
  • 大部分人高估了自己出丑时被记住的概率
  • 通州宠物寄养寄养多少钱一天?哪家好?价格+通州宠物寄养寄养基地分享 - 品牌2025
  • 在OSPF中,哪些情况会导致邻居关系无法建立?‌
  • 通州、朝阳宠物训练哪家好?2026年通州、朝阳宠物训练基地分享 - 品牌2025
  • 基于Java+SpringBoot+SSM,SpringCloud智能垃圾分类助手系统(源码+LW+调试文档+讲解等)/智能垃圾分类软件/垃圾分类助手/智能分类系统/垃圾分类智能应用
  • 2026年通州狗狗训练哪家好?通州狗狗训练哪家比较专业正规 - 品牌2025
  • 2026年北京宠物寄养哪家好?春节北京宠物寄养专业正规基地名单 - 品牌2025
  • 巴菲特的竞争优势理论:护城河的重要性
  • 如何在基于MCU的边缘AI应用场景中实现高性能、低功耗推理!
  • 谷歌大面积封禁OpenClaw用户账号
  • 短期记忆在教育AI中的应用:个性化学习的关键
  • JSBridge在Electron Web中的应用:跨平台开发的通信解决方案
  • 【毕业设计】SpringBoot+Vue+MySQL 毕业就业信息管理系统平台源码+数据库+论文+部署文档
  • 【2025最新】基于SpringBoot+Vue的web影院订票系统管理系统源码+MyBatis+MySQL
  • SpringBoot+Vue 流浪动物救助网站平台完整项目源码+SQL脚本+接口文档【Java Web毕设】
  • 流程工业MES生产执行与APC先进控制系统建设方案
  • 基于Java+SpringBoot+SpringBoot健康指导平台(源码+LW+调试文档+讲解等)/健康咨询服务平台/健康管理平台/健康资讯平台/健康指导服务/健康指导网站
  • 基于Java+SpringBoot+SpringBoot校园“财递通”快递代取系统(源码+LW+调试文档+讲解等)/校园快递代取服务/校园快递代取平台/校园快递助手/财递通系统/校园财递通服务
  • 2025年德国电气与电子产业出口额达2575亿欧元创历史新高
  • 自定义Flutter TabBar的艺术
  • 动态调整文本字体大小的JavaScript技巧