- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
将我的脚本传递到可执行文件时遇到了一些麻烦,但我终于成功了。主要问题是 PyInstaller 不会将图像加载到 GUI。
它应该是这样的:
它是这样的:
我似乎找不到问题,这是 .spec 文件:
a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'programa.py'],
pathex=['img', 'C:\\Users\\Poblet\\ManGet\\HeyMang\\pyinstaller'])
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=1,
name=os.path.join('build\\pyi.win32\\Hey Mang!', 'Hey Mang!.exe'),
debug=False,
icon='heymang.ico',
strip=False,
upx=True,
console=False )
coll = COLLECT( exe,
Tree('C:\\Users\\Poblet\\ManGet\\HeyMang\\pyinstaller\\img'),
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name=os.path.join('dist', 'Hey Mang!'))
app = BUNDLE(coll,
name=os.path.join('dist', 'Hey Mang!.app'))
它应该抓取这些图像,就像它在这里所说的:
Warnings written to C:\Users\Poblet\ManGet\HeyMang\pyinstaller\Hey Mang!\warnHey Mang!.txt
checking PYZ
rebuilding outPYZ1.toc because outPYZ1.pyz is missing
building PYZ outPYZ1.toc
checking PKG
rebuilding outPKG3.toc because outPKG3.pkg is missing
building PKG outPKG3.pkg
checking EXE
rebuilding outEXE2.toc because Hey Mang!.exe missing
building EXE from outEXE2.toc
I: SRCPATH [('heymang.ico', None)]
I: Updating icons from ['heymang.ico'] to c:\users\poblet\appdata\local\temp\tmpr34zmp
I: Writing RT_GROUP_ICON 0 resource with 76 bytes
I: Writing RT_ICON 1 resource with 1128 bytes
I: Writing RT_ICON 2 resource with 4264 bytes
I: Writing RT_ICON 3 resource with 9640 bytes
I: Writing RT_ICON 4 resource with 16936 bytes
I: Writing RT_ICON 5 resource with 67624 bytes
它们在文件夹中,但由于某种原因它们无法工作。
整个源代码(减去 PyInstaller 文件)是 here .
感谢您的帮助。
最佳答案
我能够解决这个问题,这对其他人也应该有帮助:
使用以下命令创建 .spec 文件:
python Makespec.py --noconsole --icon="youricon.ico" --name="App name" program.py
打开 .spec 文件(例如:应用程序名称/应用程序名称.spec),您应该会看到如下内容:
a = Analysis([
os.path.join(HOMEPATH,'support\\_mountzlib.py'),
os.path.join(HOMEPATH,'support\\useUnicode.py'),
'program.py'
], pathex=[
'C:\\Your\\User\\Path\\To\\pyinstaller'
])
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
exclude_binaries=1,
name=os.path.join('build\\pyi.win32\\App Name', 'App Name.exe'),
debug=False,
strip=False,
upx=True,
console=False , icon='youricon.ico'
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name=os.path.join('dist', 'Hey Mang!')
)
app = BUNDLE(coll, name=os.path.join('dist', 'Hey Mang!.app'))
在a.binaries之前你应该添加这段代码:
Tree('C:\\Your\\App\\Path\\To\\Images'),
因此当 PyInstaller 读取 .spec 文件时,编译器会将图像传递到 dist 目录。
现在我们需要创建 .qrc 文件,它将加载我们的图像。这个文件应该看起来像这样:
<RCC>
<qresource prefix="/" >
<file>img/image1.png</file>
<file>img/image2.png</file>
<file>img/image3.png</file>
</qresource>
</RCC>
显然是用你的图片。这需要编译成.py格式,使用以下命令:
pyrcc4 -o images.qrc images_qr.py
最后,我们需要将其添加到我们的脚本中,例如:
import images_qr
...
self.setWindowIcon(QtGui.QIcon(':/img/image1.png')) # The colon must be there
一旦你编译你应该能看到图像就好了,像这样:
希望对遇到同样问题的大家有所帮助。请记住提供正确的图像路径并在图像中添加冒号。
关于python - PyInstaller 不会将 PyQt 的图像加载到 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11534293/
我现在已经用 PyQt 做了几个项目,而且我越来越熟悉 Qt 采用的模型/ View 思想流派。我已经将它用于列表和表格 View 之类的东西,它们背后有一个自定义模型来显示和操作数据。我使用委托(d
import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class MainWindow(QMainWindow):
使用下面的示例代码(受 here 的严重影响),右键单击上下文菜单并没有真正正确对齐。 从屏幕截图中可以看出,生成的菜单在鼠标光标上方相当多的位置。我希望菜单的左上角与鼠标指针完全对齐。 有没有办法对
所以我创建了一个自定义上下文菜单,但我想根据某些值将树小部件的某些行中的某些项目灰显。如何禁用菜单上的项目? myUI.setContextMenuPolicy( Qt.CustomContextMe
是否可以禁用 QComboBox在 pyqt 中,就像我们可以在 Win Forms(C#) 中那样做,因为我在 QComboBox 中找不到任何选项手动的。我想启用 QcomboBox仅当管理员登录
我想将 QComboBox 与元组中的“键”和“值”一起使用,该元组类似于 django 模型中使用的元组。例如,我对一个人的性别有以下结构。 SEX_CHOICES = (('M', 'Male')
是否可以让 Altair 或 Vega(-Lite) 渲染到 PyQt 小部件,类似于支持多个后端的 Matplotlib?我知道我可以使用 Qt WebView 小部件来呈现带有 Vega 嵌入的网
在下面的示例代码中(受 here 的影响很大),我希望选择单击单元格的整行而不是单个单元格。如何更改代码以合并它? import re import operator import os import
我正在尝试禁用关闭“x”按钮,并且我认为通过将 DockWidgetFeature 设置为仅可移动和可 float 即可工作。 def CreateDockWidget (self): Pan
我已经按照 Yasin Uludag 的一些有用的在线教程来尝试使用 PyQt(或者更确切地说是 PySide)来创建一个简单的 TreeView ,但是我在使用工具提示时遇到了问题。在以下代码中,工
我正在尝试创建一个场景,我需要从 mousePressEvent 位置画线到最新的鼠标 moveposition 这意味着我需要调用 paintEvent 来自 mousePressEvent ,这可
是Python 3的组合和 PyQt 4受到推崇的?有没有其他选择? 最佳答案 我不明白为什么不,有一个 version available对于正常工作的 Python 3,如果你真的需要 Qt,唯一
我正在尝试显示从二进制文件中读取的图像数据(我编写了用于从文件中检索此数据并将其存储为图像以供 QImage() 使用的代码)。我想做的是将 slider 连接到图形 View 小部件,以便当您移动
我已经准备了很多关于如何在 python 和 pyqt 中将多个信号连接到同一个事件处理程序的帖子。例如,将多个按钮或组合框连接到同一功能。 许多示例展示了如何使用 QSignalMapper 执行此
我有一个 PyQt 主窗口,当用户按下某个按钮时,我需要从中获取一串用户输入。 这是我的用户输入窗口代码: class InputDialog(QtGui.QDialog): ''' t
编辑: 以下 buildout.cfg 用于构建 Qt、PyQt 和 SIP [buildout] parts = pyqt [pyqt] recipe = zc.recipe.cmmi ur
我目前正在开发一个应用程序,该应用程序可以使用 PyQt 访问 sqlalchemy 数据库并将其内容显示到 TableView 或其他一些小部件中。现在为了简单起见,我们只说这是一个电话簿,上面有姓
使用我现在拥有的代码,我可以成功地播放文件中的 .mp3 数据。但是我需要使用 QtCore.QBuffer(不是来自文件)播放相同的数据。当我使用文档的示例时,它会出现意外类型的 QBuffer 错
安装 sip 后,我在尝试安装 PyQt-x11-gpl-4.11 时不断收到这个可爱的错误消息。 mycommandline$ python configure-ng.py --verbose Qu
我正在为一个项目使用 PyQt。但并非突然间我收到一个错误: QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt
我是一名优秀的程序员,十分优秀!