<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>嵌入式 &#8211; 天地一沙鸥</title>
	<atom:link href="https://haoluobo.com/tag/%e5%b5%8c%e5%85%a5%e5%bc%8f/feed/" rel="self" type="application/rss+xml" />
	<link>https://haoluobo.com</link>
	<description>to be continue....</description>
	<lastBuildDate>Wed, 14 Dec 2022 01:49:29 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>使用Python做嵌入式开发</title>
		<link>https://haoluobo.com/2022/11/python-for-embedded-systems/</link>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Wed, 30 Nov 2022 06:22:00 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[嵌入式]]></category>
		<guid isPermaLink="false">https://haoluobo.com/?p=12331</guid>

					<description><![CDATA[出于性能的考虑，传统的嵌入式开发都以C、C++为主。如今嵌入式设备的性能早已今非昔比，开发工具的选择方面也有了 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>出于性能的考虑，传统的嵌入式开发都以C、C++为主。如今嵌入式设备的性能早已今非昔比，开发工具的选择方面也有了更大的自由度。对于非性能敏感的业务，Go、Python等开发语言引入的开发速度提升还是非常诱人。Python有着丰富的开发资源，在系统资源足够的情况下，Python在嵌入式环境下有着不错的开发体验。</p>



<h2 class="wp-block-heading">性能</h2>



<p>同Python高效的开发速度相对应的是Python的运行速度非常的慢，即使在脚本语言里Python也是最慢的一档。如果你的程序需要高性能，Python显然是不合适的。即使不需要高性能，也需要特别注意以保证用户体验。</p>



<p>使用的库尽量精简。在PC下Python的启动速度不会有明显的感觉，但在嵌入式设备下，用到的库多了后，第一个明显的感觉就是启动时间变长。如果用到的库多，启动时间甚至会超过10秒。嵌入式环境下引入一个新库需要更为谨慎，平衡好开发体验及性能影响。</p>



<h2 class="wp-block-heading">程序打包（应用分发）</h2>



<p>Python在跨平台方面做的非常优秀，大多情况下可以不需要嵌入式设备，直接本地开发调试。但程序发布的时候还需要针对应用平台就行打包。</p>



<p>pex会把所有的依赖和你自己的代码打包成一个.pex为后缀的可执行文件。在运行环境下直接执行该文件即可。由于开发环境的构架和运行环境的架构不一致，可以通过Docker容器就行程序的pex打包。</p>



<h2 class="wp-block-heading">代码保护</h2>



<p>对于商业项目，必要的代码保护还是有一定的必要。代码的保护可以选择下面几种方式。</p>



<ol class="wp-block-list">
<li>编译成pyc
<ul class="wp-block-list">
<li>使用命令 `python3 -m compileall -b ./;find ./ -name &#8220;*.py&#8221; -delete` 将代码编译成pyc，并删除py文件。</li>



<li>该做法可以提供最低限度的代码保护。pyc还是可以较容易的反编译成py文件。</li>
</ul>
</li>



<li>使用代码加密（混淆）工具对源代码进行加密。
<ul class="wp-block-list">
<li>开源的代码加密工具都缺乏维护，很久未更新。如果有代码加密需求，建议使用商业工具。<a href="https://github.com/dashingsoft/pyarmor" target="_blank" rel="noreferrer noopener">pyarmor</a></li>
</ul>
</li>



<li>使用 <a rel="noreferrer noopener" href="https://cython.org/" data-type="URL" data-id="https://cython.org/" target="_blank">Cython</a> 、<a rel="noreferrer noopener" href="https://github.com/Nuitka/Nuitka" data-type="URL" data-id="https://github.com/Nuitka/Nuitka" target="_blank">Nuitka</a> 等工具将代码编译成二进制文件。
<ul class="wp-block-list">
<li>相比 Cython，Nuitka的使用要简单很多，建议优先使用Nuitka。需要注意的是使用 Nuitka 后内存占用率会比直接用Python解释器高大概 1/3 。</li>



<li>Nuitka的编译也可在Docker容器中进行。</li>
</ul>
</li>
</ol>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
