Python GUI 应用程序重新分发

发布于 2024-07-06 02:12:05 字数 345 浏览 9 评论 0原文

我需要开发一个中小型桌面 GUI 应用程序,由于时间限制,最好使用 Python 作为选择语言。

假设用户没有安装有效的 Python 并且显然也没有我正在使用的 GUI 库,那么我有哪些 GUI 库选择可以让我独立重新分发应用程序?

另外,我将如何为每个目标操作系统将所有内容打包成合理大小的二进制文件? (我的主要目标是 Windows 和 Mac OS X)

补充: 我一直在研究 WxPython,但我发现了很多使用 cx_freeze 打包它并获得 30mb+ 二进制文件的恐怖故事,并且没有关于如何实际进行打包以及如何值得信赖的真正建议这是。

I need to develop a small-medium sized desktop GUI application, preferably with Python as a language of choice because of time constraints.

What GUI library choices do I have which allow me to redistribute my application standalone, assuming that the users don't have a working Python installation and obviously don't have the GUI libraries I'm using either?

Also, how would I go about packaging everything up in binaries of reasonable size for each target OS? (my main targets are Windows and Mac OS X)

Addition:
I've been looking at WxPython, but I've found plenty of horror stories of packaging it with cx_freeze and getting 30mb+ binaries, and no real advice on how to actually do the packaging and how trust-worthy it is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

谁对谁错谁最难过 2024-07-13 02:12:06

Python 有一个名为 TKinter 的嵌入式 GUI 工具包,它基于 TCL 编程语言的 Tk 库。 它非常基础,不具备您在 Windows Forms 或 GTK 中期望的所有功能,但如果您必须拥有独立于平台的工具包,考虑到您也不希望二进制文件增长那么多,我认为没有其他选择。

Tkinter 一点也不难使用,因为它没有数百万个小部件/控件和选项,并且是大多数 Python 发行版(至少在 Windows、OSX 和 Linux 上)中包含的默认工具包。

GTKQT 更漂亮、更强大,但它们对你来说有一个很大的缺点:它们很重并且依赖于第三方库,特别是 GTK,它有很多依赖项,这使得将其嵌入到你的程序中分发有点困难。软件。

至于二进制文件的创建,我知道有 py2exe 可以将 python 代码转换为 win32 可执行代码(.exe),但我不确定 OSX 是否有类似的东西。 您是否担心因为人们可以看到源代码,或者只是为了将所有内容捆绑在一个包中? 如果您只想捆绑创建独立可执行文件所需的所有内容,您可以轻松创建一个安装程序:

Creating distributable in python

这是有关如何在完成后分发软件的指南。

Python has an embedded GUI toolkit named TKinter which is based on Tk library from TCL programming language. It is very basic and does not have all the functionality you expect in Windows Forms or GTK for example but if you must have platform independent toolkit I see no other choice taking in mind that you also dont want to grow that much the binary.

Tkinter is not hard at all to use since it doesnt have millions of widgets/controls and options and is the default toolkit included in most python distributions, at least on Windows, OSX and Linux.

GTK and QT are prettier and more powerful but they have a one big disadvantage for you: they are heavy and deppend upon third libraries, especially GTK which has a lot of dependencies that makes it a little hard to distribute it embeded in your software.

As for the binary creation I know there is py2exe which converts python code to win32 executable code (.exe's) but im not sure if there is something similar for OSX. Are you worried because people could see the source code or just so you can bundle all in a single package? If you just want to bundle everything you dont need to create a standalone executable, you could easily create an installer:

Creating distributable in python

That's a guide on how to distribute your software when it's done.

北渚 2024-07-13 02:12:06

Windows 版 http://Gajim.org 使用 python 和 PyGtk。 你可以检查一下,他们是怎么做到的。 另外,还有用于 GUI 的 PyQt(以及前面提到的 wxpython)。

http://Gajim.org for Windows uses python and PyGtk. You can check, how they did it. Also, there's PyQt for GUI (and wxpython mentioned earlier).

流殇 2024-07-13 02:12:06

我没有为 Windows 以外的任何平台构建独立应用程序的经验。

也就是说:

Tkinter:与 py2exe 一起工作得很好。 Python Megawidgets(Tkinter 的“扩展库”)也可以正常工作,但它通过动态导入做了一些时髦的事情,因此您需要将所有组件组合成一个大文件“pmw.py”并将其添加到您的项目中(嗯,您还将拥有 pmwblt.py 和 pmwcolor.py)。 在某处有关于如何执行此操作的说明(在 py2exe wiki 或 PMW 文档中)。 Tix(Tk 的扩展,可以与 Tkinter 一起使用)不能与 py2exe 一起使用,或者至少这是我四年前的经验。

wxPython 也可以与 py2exe 一起正常工作。 我刚刚检查了我拥有的一个应用程序; 整个发行版大小约为 11MB。 其中大部分是 wx DLL 和 .pyd 文件,但我不知道如何避免这种情况。 如果您的目标是 Windows XP,则需要在 setup.py 中包含清单,否则它看起来会很难看。 有关详细信息,请参阅此电子邮件

I don't have any experience building stand-alone apps for any platform other than Windows.

That said:

Tkinter: works fine with py2exe. Python Megawidgets (an "expansion library" for Tkinter) works fine also, but it does funky things with dynamic imports, so you need to combine all the components into a big file "pmw.py" and add it to your project (well, you'll also have pmwblt.py and pmwcolor.py). There are instructions for how to do this somewhere (either on py2exe wiki or in the PMW docs). Tix (an extension to Tk that you can use with Tkinter) doesn't work with py2exe, or at least that was my experience about four years ago.

wxPython also works fine with py2exe. I just checked an app I have; the whole distribution came to around 11MB. Most of that was the wx DLLs and .pyd files, but I can't see how you'd avoid that. If you are targetting Windows XP, you need to include a manifest in your setup.py or else it will look ugly. See this email for details.

东北女汉子 2024-07-13 02:12:06

我自己使用过 py2Exe - 它非常简单(至少对于小型应用程序来说)。

I've used py2Exe myself - it's really easy (at least for small apps).

述情 2024-07-13 02:12:06

我熟悉的组合:wxPython、py2exe、upx

解决您最后一个关于发行版大小的担忧的关键是使用 upx 来压缩 DLL。 看起来他们支持 MacOS 可执行文件。 首次加载 DLL 时,您将付出初始解压代价。

Combination that I am familiar with: wxPython, py2exe, upx

The key to resolving your last concern about the size of the distribution is using upx to compress the DLLs. It looks like they support MacOS executables. You will pay an initial decompression penalty when the DLLs are first loaded.

以为你会在 2024-07-13 02:12:05

http://wiki.wxpython.org/CreatingStandaloneExecutables

它不应该那么大,除非你设法包括 wx 的调试版本。
我似乎记得 python.dll 大约有 4Mb,wx 也有类似的大小。

http://wiki.wxpython.org/CreatingStandaloneExecutables

It shouldn't be that large unless you have managed to include the debug build of wx.
I seem to rememebr about 4Mb for the python.dll and similair for wx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文