使用Pyinstaller 2.0,PySide 1.1.2绑定和Qt 4.8时如何在应用程序中包含图标 [英] How to include icons in application when using Pyinstaller 2.0 ,PySide 1.1.2 Bindings and Qt 4.8

查看:166
本文介绍了使用Pyinstaller 2.0,PySide 1.1.2绑定和Qt 4.8时如何在应用程序中包含图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么样的脚本看起来像

what script looks like

什么样的应用程序应该看起来像

what working app should look like

发布之前,我已经看过以下问题,并试图将其用作指导以使我的脚本正常工作,但这只是边际用途

Before posting I have looked at the following question and tried to use it as a guide to make my script work properly but it was of marginal use

PyInstaller不会将PyQt的图像加载到GUI

最好的做法是,将我的图标包含在结果目录中,如下所示:

the best it did was include my icons in the resulting directory as follows

(此处包含图标)

和以下一个 我什至不知道它在说什么,但是我知道如果我知道,它可以解决我的问题. 它实际上在做什么 使用PyInstaller(--onefile)捆绑数据文件

and the following one I have no idea what it is even saying but I feel it can solve my problem if I knew what it was actually doing, Bundling data files with PyInstaller (--onefile)

我有rtfm,不幸的是,其中大多数超过了我的头.下一节 我认为与我的问题有关

I have rtfm and most of it goes above my head unfortunately. The following section which I think pertains to my question

http://www.pyinstaller.org/wiki/Recipe/CollectDatafiles

我不知道如何在我的规格文件中实际实现它

I have no idea how to actually implemet it in my spec file

以下内容相同 http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw#accessing-data-files

我已经完成了以下工作及其变体,包括使用-F参数

I have done the following and variations of it including using the -F parameter

我使用pyside-uic.exe转换了mainWindow.ui文件,将其转换为mainGui.py文件

I converted my mainWindow.ui file using pyside-uic.exe to convert it into mainGui.py file

然后将icons.qrc转换为icons_rc.py 使用pyside-rcc.exe进行转换

then converted icons.qrc into icons_rc.py using the pyside-rcc.exe to make the conversion

(注意:我将exe的副本最初放在PySide文件夹中后转换了文件 放入路径中的C:\ Python27 \ Scripts文件夹中,以便可以从任何地方调用它)

(note: I converted the file after putting a copy of the exe originally in the PySide folder into my C:\Python27\Scripts folder which is in my Path so that I can call it from anywhere)

我将图标存储在图标文件夹

I store my icons in the icons folder

使用Pyinstaller在控制台中生成可执行文件,我使用了以下命令 制作我的规格文件

to make the executable in my console using Pyinstaller I have used the following command to make my spec file

C:\ Pyinstaller-2.0> python utils \ Makespec.py --windowed --name ="16TangoTest" C:\ Exmake \ 16MainWindowVideo.py

C:\Pyinstaller-2.0> python utils\Makespec.py --windowed --name="16TangoTest" C:\Exmake\16MainWindowVideo.py

一旦创建了规格文件,我将从pyinstaller文件夹中剪切并添加它 到我的Exmake文件夹

Once spec file is made I cut it from the pyinstaller folder and add it to my Exmake folder

然后我使用它修改它以包含我的图标文件夹

then I modify it to include my icons folder using

树(C:\ Exmake \ icons), 并将其附加以收集 在a.binaries上方的行中

Tree(C:\Exmake\icons), and append it to collect in the line above a.binaries

手册和上面的第一个答案表明我必须修改我的规范文件,以便pyinstaller可以像在下图中所做的那样看到/找到我的图标

The manual and the first answer above indicate that I have to modify my spec file so that pyinstaller sees / finds my icons as I've done in the picture below

所做的只是将我的图标包含在dist目录中 应用程序仍然无法像上面的第一张图片一样显示它们

all it did was include my icons in the dist directory with the application still not displaying them as in the 1st picture above

然后我通过在控制台中运行以下命令来生成可执行文件 C:\ Pyinstaller-2.0> python pyinstaller.py C:\ Exmake \ 16TangoTest.spec 这样就可以在第一张图片中看到该文件夹​​,其中包含图标,但是 文件夹,而不是运行时的应用程序

Then I make the executable by running the following in the console C:\Pyinstaller-2.0>python pyinstaller.py C:\Exmake\16TangoTest.spec and that makes the folder that you see in the first picture, the icons are included but the folder but not the application when it is run

推荐答案

好,最后一个答案,事实证明Qt需要以下文件qico4.dll对于Qt5可能有所不同,当在QtDesigner中创建GUI时,它会自动加载所有需要的插件,包括上面的图像插件,但是将文件转换为python脚本时,它不包括该插件,除非您在脚本中添加以下代码

Ok, final answer, it turns out that Qt needs the following file qico4.dll might be different for Qt5, when making your GUI in QtDesigner it automatically loads all the plugins it needs including the above image plug in, however when converting the file into a python script it does not include it unless you add the following code in your script

#:Loads the qico plug-in lets you use .ico icons
QPlugin = QPluginLoader("qico4.dll")

下面的文字可能会在不同情况下帮助其他人

The text below might help others in different situations

这是对我自己的问题的部分回答,在上面我要感谢Blender,简短的回答是您必须将图标从.ico转换为.png文件,问题是您必须完成整个过程再次制作您的应用程序,这些是我采取的步骤 我首先进入我的图标所在的文件夹,然后将froom .ico转换为.png图标,我使用了在这里

This is a partial answer to my own question I would like to thank Blender up above, the short answer is you have to convert your icons from .ico into .png files, the problem is that you have to do the whole process of making your application again, these are the steps that I took I first went into the folder where I had my icons and converted them froom .ico into .png icons, I used the tool I got here http://www.towofu.net/soft/e-aicon.php I found this in this site..I love stackoverflow..ahem

一旦将图标转换为.png格式,则必须在其中拥有图标信息的地方更改.qrc文件,并使用新的图标信息进行更新,我建议您从头开始进行操作.有了新的icons.qrc文件后,您就可以在QtDesinger中打开.ui文件,并从中删除旧图标的所有实例,然后继续使用图标/资源文件使用新格式化的图标来更新它们.

once your icons are converted to the .png format you must change your .qrc file where you have your icon information and updated with the new icon information, I advise doing it from scratch; once you have your new icons.qrc file you then open your .ui file in QtDesinger and erase all the instances of your old icons from it and then proceed to update them with the newly formatted icons using the icon/resource file.

更新所有图标后,将其保存并继续转换工作流程,即使用pyside-uic.exe转换器将"your_file.ui"转换为"newly_converted_file.py".

After all of your icons have been updated, you save it and continue with the conversion workflow, i.e convert your 'your_file.ui' to 'newly_converted_file.py' using the pyside-uic.exe converter.

接下来,使用pyside-rcc.exe命令将"icons.qrc"文件转换为"icons_rc.py"

Next convert your 'icons.qrc' file into a 'icons_rc.py' using the pyside-rcc.exe command

在此过程结束时,您只需要带有.png图标的icons文件夹 您的icons_rc.py文件和应用程序脚本.

at the end of this process you should only need your icons folder with your .png icons your icons_rc.py file and your application script.

之后,您可以按照手册继续使用Pyinstaller-2.0.

After that you can continue to use the Pyinstaller-2.0 as per the manual..

正如我所说的,这是部分答案,因为它可以工作,但是,如果其他人可以告诉我或向我解释如何使其与我的原始.ico文件一起工作,那么我怀疑我不必费尽周折整个过程再次

As I've said it is a partial answer because it works, however if someone else could tell me or explain to me how to make it work with my original .ico files then I suspect I would not have to go trough the whole process again

在进行更多研究后,此页面特别有用 http://qt-project.org/forums/viewthread/17342

Upon more research this page was especially helpful http://qt-project.org/forums/viewthread/17342

所以我进入我的Qt4.8文件夹并搜索qico4.dll,并在我的脚本所在的文件夹中进行了复制,并且该应用程序运行良好,如果我能找到一种在其中包含它的方法然后我的脚本我想我会得到一个完整的答案,问题似乎出在Qt而非Pyinstaller上,似乎它需要知道dll才能处理.ico文件

so I went into my Qt4.8 folder and did a search for qico4.dll and made a copy of it in the folder where my script is located and the application ran perfectly, If I can find a way to include it inside my script then I think I will have a complete answer, the problem seems to be with Qt and not Pyinstaller, it seems that it needs to be aware of the dll in order to process .ico files

这篇关于使用Pyinstaller 2.0,PySide 1.1.2绑定和Qt 4.8时如何在应用程序中包含图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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