来自 python 脚本的最小可能的 Windows 可执行文件
我看过一些项目,例如 py2exe 和其他几个项目。但我想要小于 1mb 的小尺寸就很酷,但小于 300kb 则更理想。是否有任何项目可以将 python extern 转换为 C 编译器,甚至将 python 转换为 C? 也许只有一个非常小的 python 解释器,我可以只添加所需的库? (我尝试了一个,它似乎并不是真正的“python”)
我已经看过很多选项,但我还没有正确尝试它们......你能推荐什么? 如果回报(小规模)值得,我愿意将精力投入到更复杂的过程中,但我需要缩小列表范围。
I've looked at some projects like py2exe and a couple other ones. But I want really small under 1mb would be cool but under 300kb would be ideal. Are there any project to possibly extern python into a C compiler or even convert python to C?
Maybe there is just a really small python interpreter that I could add only the required libraries to? ( I tried one, it didn't really seem to be "python")
I've looked at a lot of options but I haven't tried them out properly... What can you recommend?
I am willing to put the effort into a more complex process if the payoff(small size) is worth it, but I need to narrow down the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
中的 Shedskin 解决方案将 Python 编译为机器代码是否可行? 是您要查找的内容,但它不会编译任意 python 代码。而且它不是编译为 C 而是编译为 C++。
The Shedskin solution in Is it feasible to compile Python to machine code? is what you look for however it is not compile an arbitrary python code. And it is not compile to C but to C++.
我的意思是,您将使用 python 获得的最接近的是 py2exe 和 UPX 创建 exe 但不要将任何内容捆绑到其中相反,创建一个库,然后使用 upx 并进行最佳压缩。它的开销很小,并且可以从您的最终产品中减少几MB。这不是最好的方法,但它是其中之一。
另一种选择是用 C 或 C++ 编写一个 snub 启动器来启动 python 解释器并运行源代码。虽然这会小得多,但制作起来可能会复杂得多,如果您想遵循这种方法,那么这个 链接 会帮助你。
I mean the closest you will get with python is py2exe and UPX Create the exe but don't bundle anything to it instead make a library then use upx and do the best compression. It has little overhead and can trim another few mb off your final product. Its not the best way but its one of them.
The other option would be to write a snub launcher in C or C++ to fire up a python interpreter and run your source code. While this would be much smaller it would probably be far more complicated to make, if you are looking to follow this method then this link will help you with that.