在另一台计算机上运行冻结的pyqt应用程序时未显示的图像

Bro*_* S. 4 pyqt pyqt4 cx-freeze python-3.x

我有一个PyQt4程序,我用cx_freeze冻结了.我遇到的问题是,当我创建一个QGraphicsPixmapItem,它正在获取它的'像素图由SVG文件制作时,Item没有问题,但是Pixmap没有加载所以没有图像只是场景中的项目.令我困惑的是,只有当我在不同于构建exe的计算机上运行它时,才会发生这种情况.当我在构建它的计算机上运行exe时,程序运行完美.即使我尝试在计算机上安装了所有必需的python组件和pyqt组件的计算机上运行它,如果它不是构建它的计算机,则不会从svg文件加载pixmap.我不确定这是否是我的cx_freeze setup.py文件的问题,或者如果我需要更改主代码中的内容,那么任何帮助或只是指向正确的方向将是伟大的.我的感觉是,当cx_freeze构建它时,某些东西会搞砸,所以我将粘贴下面的setup.py文件的内容.我也使用Python v3.1在Windows上运行.

from cx_Freeze import setup, Executable

files = ['drawings\\FULL', 'drawings\\PANEL', 'data.csv', 'panelData.csv']
binIncludes = ['C:\\Python31\\Lib\\site-packages\\PyQt4\\bin\\QtSvg4.dll']
includes = ['main', 'PunchDialog', 'ArrayDialog', 'PricingDialog', 'FontAndInputDialog', 'PanelSelector', 'PyQt4', 'os', 'sys', 'ctypes', 'csv']
packages = ['drawings']
path = ['C:\\Users\\Brock\\Documents\\Programming\\PanelDesigner\\DrawingFirst', 'C:\\Python31\\Lib', 'C:\\Python31\\Lib\\site-packages', 'C:\\Python31\\DLLs']

setup(
        name = 'PanelBuilder',
        version = '1.0',
        description = 'Allows user to draw custom panel layouts.',
        author = 'Brock Seabaugh',
        options = {'build_exe': {'packages':packages, 'path':path, 'include_files':files, 'bin_includes':binIncludes, 'includes':includes}},
        executables = [Executable('PanelBuilder.py')])
Run Code Online (Sandbox Code Playgroud)

PS.这是我的文件层次结构(如果有帮助的话):

\DrawingFirst
    Main .py file
    All .py files for all custom dialogs used
    \drawings
        some modules used
        \FULL
            A bunch of SVG files used
        \PANEL
            More SVG files used
Run Code Online (Sandbox Code Playgroud)

auk*_*ost 6

这是我过去遇到的一个令人讨厌的问题.让我引用http://www.py2exe.org/index.cgi/Py2exeAndPyQt :(我知道你使用的是cx_freeze,但我相信你可以调整你的脚本)

PyQt4和图像加载(JPG,GIF等)

PyQt4使用插件来读取这些图像格式,因此您需要将文件夹PyQt4\plugins\imageformats复制到 appdir\imageformats.与上面的情况一样,您可以使用data_files.这不适用于bundle_files.

如果无法访问插件,则在以这些格式加载图像时,QPixmap.load/loadFromData将返回False.

testapp.py:

from PyQt4 import QtGui, QtSvg
import sys

app = QtGui.QApplication([])
wnd = QtSvg.QSvgWidget()
wnd.load("flower.svg")
wnd.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

setup.py:

from cx_Freeze import setup, Executable
files = ['flower.svg']
includes = ['sip', 'PyQt4.QtCore']
setup(
        name = 'Example',
        version = '1.337',
        description = 'Allows user to see what I did there.',
        author = 'something',
        options = {'build_exe': {'include_files':files, 'includes':includes}},
        executables = [Executable('testapp.py')])
Run Code Online (Sandbox Code Playgroud)

我在Windows 7计算机上创建了此测试应用程序并将其复制到Windows XP计算机上.我没有复制任何dll - 它就像那样工作.