Python可以在多个平台上工作,可以用于桌面和web应用程序,因此我得出结论,有某种方法可以将它编译成Mac、Windows和Linux的可执行文件。

问题是我不知道从哪里开始或如何写一个GUI与它,谁能在这一点上提供一些光,并指出我在正确的方向请?


当前回答

另一个系统(在接受的答案中还没有提到)是PyInstaller,它适用于我的一个PyQt项目,而py2exe不能。我发现它更容易使用。

http://www.pyinstaller.org/

Pyinstaller基于Gordon McMillan的Python Installer。现在已经没有了。

其他回答

你可以做三件事:

首先要做的是找到一个GUI设计器,它可以将其代码作为独立的应用程序(如.exe文件)启动。我使用MatDeck的一个版本(对于使用GUI设计器的人,我推荐MD Python设计器),因为我相信(我使用另一个版本,所以我不太确定。)它允许我将代码转换为独立的应用程序,这样,就不需要在每台PC上安装软件来运行程序。

The second option is partially bypassing the problem, launch the GUI as a web page. This would give you the most compatibility as most if not all OS can utilize it. Once again, you would need a GUI Designer that can convert its components into a web compatible format, I've done it once and I used the same version of MatDeck(Visionary Deck), I would not recommend MD Python Designer this time as I don't know if it can turn its GUIs into websites using web assembly whereas Visionary Deck I've tried and tested. As with all things there are most likely other software this is just one I use frequently because I work a lot with Mathematics and Physics.

第三种选择也可以绕过这个问题,但在Tkinter中进行,并确保您有一个Python IDE或只是普通的Python并运行代码,这将启动GUI。这是一个很好的解,可能是最简单的,但我不会把它归类为最短或最好的。如果你只打算在几个操作系统和电脑之间切换,这可能是你最好的选择。

我不确定这是否是最好的方法,但当我在Windows上部署Ruby GUI应用程序(不是Python,但就.exe而言有相同的“问题”)时,我只是用c#编写了一个简短的启动程序,调用我的主脚本。它编译成一个可执行文件,然后我就有了一个可执行的应用程序。

py2exe的另一个替代工具是bbfreeze,它可以为windows和linux生成可执行文件。它比py2exe更新,可以很好地处理鸡蛋。我发现,对于各种各样的应用程序,不需要配置它就能神奇地更好地工作。

另一个系统(在接受的答案中还没有提到)是PyInstaller,它适用于我的一个PyQt项目,而py2exe不能。我发现它更容易使用。

http://www.pyinstaller.org/

Pyinstaller基于Gordon McMillan的Python Installer。现在已经没有了。

您可以使用appJar进行基本的GUI开发。

from appJar import gui

num=1

def myfcn(btnName):   
    global num
    num +=1
    win.setLabel("mylabel", num)

win = gui('Test')

win.addButtons(["Set"],  [myfcn])
win.addLabel("mylabel", "Press the Button")

win.go()

请参阅appJar站点上的文档。

使用pip install appjar命令行进行安装。