为 Python 3 和 PyQt 构建可执行文件 [英] Building executables for Python 3 and PyQt

查看:44
本文介绍了为 Python 3 和 PyQt 构建可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 PyQt4 在 Python 3.1 中构建了一个相当简单的应用程序.完成后,我希望将应用程序分发到没有安装任何一个的计算机上.

我几乎只关心 Windows 平台,所以我的目标是有一个单一的可执行文件,最后可能还有一些资源文件和 .dll.

经过一番搜索,我得出的结论是

  • py2exe 仅支持 Python 2.7 及以下版本
  • pyinstaller 仅支持 Python 2.6 及以下版本
  • cx_Freeze 对我不起作用,因为我在尝试执行我成功构建的二进制文件时不断收到以下错误:
<预><代码>Y:\Users\lulz\build\exe.win32-3.1>system_shutdown.exe
回溯(最近一次调用最后一次):
文件Y:\Program Files (x86)\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py",第 27 行,在 exec(code, m.__dict__)
文件Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/system_shutdown.pyw",第 5 行,从 PyQt4 导入 QtCore
文件ExtensionLoader_PyQt4_QtCore.py",第 16 行,在 AttributeError 中:'NoneType' 对象没有属性 'modules'

所以我的问题基本上是这里的两个问题:

  1. 除了 cx_Freeze 之外,还有其他方法可以使用我的配置构建二进制文件吗?
  2. 如果没有,cx_Freeze 问题可能是什么?

如有必要,我可以提供有关第二个问题的更多信息,例如我对 cx_Freeze 的调用、我的 distutils 设置脚本等.

感谢您的帮助和评论.

解决方案

您可以通过将一行代码附加到 cx_Freeze 包中的 freeze.py 来解决此问题.

这里是这样描述的:http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00212.html

它至少对我有用:)

干杯,阿尔玛

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed.

I almost exclusively care about Windows platforms, so my goal is to have a single executable file and maybe some resource files and .dlls in the end.

Having searched around, I came to the conclusion that

  • py2exe only supports Python up to version 2.7
  • pyinstaller only supports Python up to version 2.6
  • cx_Freeze does not work for me because I keep on getting the following error when trying to execute my successfully build binary:


Y:\Users\lulz\build\exe.win32-3.1>system_shutdown.exe
Traceback (most recent call last):
File "Y:\Program Files (x86)\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in exec(code, m.__dict__)
File "Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/system_shutdown.pyw", line 5, in from PyQt4 import QtCore
File "ExtensionLoader_PyQt4_QtCore.py", line 16, in AttributeError: 'NoneType' object has no attribute 'modules'

So my problem is basically two problems here:

  1. Is there another way but cx_Freeze to build binaries with my configuration?
  2. If not, what might the cx_Freeze problem be?

I can provide more information on the second problem if necessary, like my call of cx_Freeze, my distutils setup script etc.

Thank you already for your help and comments.

解决方案

You can fix this by appending one line of code to freeze.py in your cx_Freeze package.

It is described here: http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00212.html

It worked for me at least :)

Cheers, Almar

这篇关于为 Python 3 和 PyQt 构建可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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