我有一个 PySide 应用程序,它有一个MainWindow
(一个QMainWindow
实例)的图标。当我正常运行文件时,图标是可见的,一切都很好,但是当我创建一个 exe 时py2exe
,图标不会出现。这也发生在cx_freeze
(所以我认为问题不在于py2exe
)。
该应用程序是使用设计QtDesigner
并转换为带有pyside-uic
. 我尝试将图标用作文件和资源(qrc 文件),但似乎都不起作用。
任何帮助或指示将不胜感激。
谢谢。
只要您不尝试将 Qt dll 捆绑到 library.zip 或 exe 中,kochelmonster 的解决方案就可以工作。如果您将插件放在应用程序目录的基础中,您也不需要设置库路径。
我仍然想捆绑其他所有东西,所以我排除了 qt dll 并手动添加它们。我的 setup.py 看起来像这样:
from os.path import join
_PYSIDEDIR = r'C:\Python27\Lib\site-packages\PySide'
data_files =[('imageformats',[join(_PYSIDEDIR,'plugins\imageformats\qico4.dll')]),
('.',[join(_PYSIDEDIR,'shiboken-python2.7.dll'),
join(_PYSIDEDIR,'QtCore4.dll'),
join(_PYSIDEDIR,'QtGui4.dll')])
]
setup(
data_files=data_files,
options={
"py2exe":{
"dll_excludes":['shiboken-python2.7.dll','QtCore4.dll','QtGui4.dll'],
"bundle_files": 2
...
}
}
...
)
如果您的项目使用额外的 Qt dll,您将不得不排除并手动添加它们。如果您需要加载 .ico 图像以外的其他内容,您还需要添加正确的插件。
我假设它适用于 bmp,但不适用于 png/jpg?如果是这样,则图像格式插件可能无法正确加载。
我猜想在已安装应用程序的目录中设置一个qt.conf文件并确保 plugin-dll 转到 /plugins/imageformats/ 会让事情变得更好。
我有同样的问题。经过一番调查,我找到了解决方案:(麦克有正确的想法)
cx_freeze
不复制PyQt
包含ico
图像阅读器的插件目录。以下是步骤:
setup.py
复制到您的发行版中PyQt4
application_path = os.path.split(os.path.abspath(sys.argv[0]))[0] try: if sys.frozen: plugin_path = os.path.join(application_path, "qtplugins") app.addLibraryPath(plugin_path) except AttributeError: pass
会不会与 Windows 7 的任务栏图标处理有关?
请参阅如何在 Windows 7 中设置应用程序的任务栏图标以获取答案。
您必须在发布文件夹中手动包含“qico4.dll”。在你的 setup.py 中插入:
import sys
from os.path import join, dirname
from cx_Freeze import setup, Executable
_ICO_DLL = join(dirname(sys.executable),
'Lib', 'site-packages',
'PySide', 'plugins',
'imageformats', 'qico4.dll')
build_exe = {
'include_files': [(
_ICO_DLL,
join('imageformats', 'qico4.dll'))]}
setup(name = "xxxxx",
version = "1.0.0",
...
options = { ...
'build_exe': build_exe
...},
...)