如何将 PyQt 脚本 (.py) 编译为 Windows (.exe) 和/或 linux 的单个独立可执行文件? [英] How do I compile a PyQt script (.py) to a single standalone executable file for windows (.exe) and/or linux?

查看:36
本文介绍了如何将 PyQt 脚本 (.py) 编译为 Windows (.exe) 和/或 linux 的单个独立可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始摆弄 PyQt,并从 pyqt 白皮书示例应用程序 (pastebin)

I started to fiddle with PyQt, and made a "beautiful" script from the pyqt whitepaper example app (pastebin)

它在 Windows 和 Linux 上都能完美运行(两者都已经安装了 qt 环境).

It works perfectly in Windows and Linux (with qt environment already installed on both).

现在我的问题是:由于我尝试使用 Qt,因为它是经过编译的(至少是纯旧的基于 C++ 的 Qt),我如何编译一些 .exe 文件以在 Windows 上运行它,或者在 Linux 上运行一个独立的可执行文件.

Now my question is: Since I am trying to use Qt because it is compiled (at least pure old C++ based Qt), how can I compile some .exe file to run it on Windows, or a standalone executable for Linux.

关键是我希望程序被编译,因为速度和可移植性,而不是从源代码解释,这需要在任何机器上预先设置.例如,目标之一是通过电子邮件向根本不是程序员的同事发送小型 gui 脚本.

The point is that I want the program to be compiled, because of speed and portability, instead of interpreted from source, which would require a previous setup on any machine. One of the goals, for example, is sending small gui scripts via email to coworkers who are not programmers at all.

推荐答案

如果你想完全创建一个独立的可执行文件,你可以试试这个:http://www.pyinstaller.org/.我觉得创建一个独立的可执行文件比 cx_freeze 或 py2exe(以我的经验)更好.并且易于使用(网站上提供了完整的文档).

if you want completelly create one stand alone executable, you can try this : http://www.pyinstaller.org/ . i feel it's better to create one stand alone executable than cx_freeze or py2exe (in my experience). and easy to use (full documentation available in the site).

更新:作为@SoursopTree 和@LectureMaker 的最新信息,它现在支持python 3.3 - 3.6 版本.

Update: As latest information from @SoursopTree and @LectureMaker, it now support python version 3.3 - 3.6.

更新:如果您想创建完全独立的 .exe,请传递 --onefile 参数.例如:

Update: pass --onefile argument if you want to create completely standalone .exe. in example :

pyinstaller.exe --onefile --windowed app.py

这篇关于如何将 PyQt 脚本 (.py) 编译为 Windows (.exe) 和/或 linux 的单个独立可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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