将Linux上的Python脚本打包到Windows可执行文件中 [英] Packaging a Python script on Linux into a Windows executable

查看:97
本文介绍了将Linux上的Python脚本打包到Windows可执行文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python脚本,希望将其编译为Windows可执行文件.现在, py2exe 在Windows上可以正常运行,但我希望能够在Linux上运行它.我在开发机器上安装了Windows,但是Linux是我的主要开发平台,我有点讨厌重新启动Windows以创建 .exe .我也不需要购买第二个Windows许可证即可在虚拟机(例如VirtualBox)中运行.有什么想法吗?

I have a Python script that I'd like to compile into a Windows executable. Now, py2exe works fine from Windows, but I'd like to be able to run this from Linux. I do have Windows on my development machine, but Linux is my primary dev platform and I'm getting kind of sick of rebooting into Windows just to create the .exe. Nor do I want to have to buy a second Windows license to run in a virtual machine such as VirtualBox. Any ideas?

PS:我知道 py2exe 不能完全编译python文件,而不是使用Python解释器打包脚本.但是,无论哪种方式,结果都是您不需要安装Python即可运行脚本.

PS: I am aware that py2exe doesn't exactly compile the python file as much as package your script with the Python interpreter. But either way, the result is that you don't need Python installed to run the script.

推荐答案

您看过 PyInstaller 吗?

似乎1.4之前的版本都支持交叉编译(1.5+版本中已删除了该支持).请参阅此答案,以了解如何在Wine下使用PyInstaller 1.5 +.

It seems that versions through 1.4 support cross-compilation (support was removed in 1.5+). See this answer for how to do it with PyInstaller 1.5+ under Wine.

文档说:

添加对交叉编译的支持:PyInstaller现在能够在Linux下运行时生成Windows可执行文件.有关更多详细信息,请参阅文档.

Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.

我自己没有尝试过.

我希望对您有帮助

这篇关于将Linux上的Python脚本打包到Windows可执行文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆