简体   繁体   English

如何最小化嵌入式系统的 Python 3.6 运行时?

[英]How to minimize the Python 3.6 runtime for an embedded system?

We make an ARM 9 embedded system, Linux, etc. Recently a customer asked we pre-install Python 3 for them.我们做了一个ARM 9嵌入式系统,Linux等。最近有客户要求我们为他们预装Python 3。 We worked out the cross-compile (QEMU is really magical), but the resultant build is 177Mb, so that's a no go.我们制定了交叉编译(QEMU 真的很神奇),但最终的构建是 177Mb,所以这是不行的。 What's the best plan here - we can leave off the Doc directory, and maybe the "build" dir?这里最好的计划是什么——我们可以去掉 Doc 目录,也许还有“构建”目录? I see the Lib directory is 54Mb - is it a case of picking an choosing what libs the customer needs?我看到 Lib 目录是 54Mb - 这是选择客户需要什么库的情况吗? We know very little about Python.我们对 Python 知之甚少。 To be clear, I see lots of advice about packaging Python apps - that's not what we are doing - we are packaging the Python runtime.明确地说,我看到很多关于打包 Python 应用程序的建议——这不是我们正在做的——我们正在打包 Python 运行时。 Thanks!谢谢! (directory size summary below) (目录大小汇总如下)

 1.6M ./Python-3.6.0/Mac 760K ./Python-3.6.0/Include 17M ./Python-3.6.0/build 5.4M ./Python-3.6.0/Python 8.0K ./Python-3.6.0/.github 54M ./Python-3.6.0/Lib 2.7M ./Python-3.6.0/PC 2.7M ./Python-3.6.0/Tools 6.9M ./Python-3.6.0/Objects 11M ./Python-3.6.0/Doc 824K ./Python-3.6.0/Parser 20M ./Python-3.6.0/Modules 15M ./Python-3.6.0/Programs 620K ./Python-3.6.0/PCbuild 12K ./Python-3.6.0/Grammar 5.8M ./Python-3.6.0/Misc 161M ./Python-3.6.0 177M .

A possible choice to meet your requirements may be MicroPython which is an implementation of PYthon 3 which consists of a small subset of the Python standard library.满足您要求的可能选择可能是 MicroPython,它是 PYthon 3 的实现,它由 Python 标准库的一小部分组成。 According to their website it is targeted for micro controllers and constrained environments: https://micropython.org/根据他们的网站,它针对微控制器和受限环境: https : //micropython.org/

According to their description MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with ease from the desktop to a microcontroller or embedded system.根据他们的描述,MicroPython 的目标是尽可能与普通 Python 兼容,以允许您轻松地将代码从桌面传输到微控制器或嵌入式系统。 Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.然而,它足够紧凑,可以在仅 256k 的代码空间和 16k 的 RAM 内运行。

There is an online project that puts an implementation of MicroPyton in an Arm Cortex M4 based embeeded system may also prove helpful: https://github.com/micropython/micropython/wiki有一个在线项目将 MicroPyton 的实现放在基于 Arm Cortex M4 的嵌入式系统中也可能会有所帮助: https : //github.com/micropython/micropython/wiki

We removed the following:我们删除了以下内容:

  1. python3-tests python3-测试
  2. libpython3.8-staticdev libpython3.8-staticdev
  3. python3-*src python3-*src
  4. python3-*dbg python3-*dbg
  5. python3-*dev python3-*开发
  6. All the .pyc files (they can be recompiled after install)所有.pyc文件(安装后可以重新编译)

We chose not to go ahead with the following:我们选择不进行以下操作:

  1. Removing "unneeded" modules: may break the dependencies of 3rd party libraries删除“不需要的”模块:可能会破坏 3rd 方库的依赖关系
  2. UPX binary packer: the zipped installation media is the same size, so this only slows down startup UPX 二进制打包程序:压缩的安装介质大小相同,因此这只会减慢启动速度
  3. python source file minification: produced broken code, as we found out when regenerating the .pyc with python3 -m compileall . python 源文件缩小:产生了损坏的代码,正如我们在使用python3 -m compileall .重新生成.pyc时发现的那样python3 -m compileall .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM