Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

python 3.x - Images not showing when running a frozen pyqt app on another computer

I have a PyQt4 program that I froze using cx_freeze. The problem I am having is when I make a QGraphicsPixmapItem, which it is getting its' pixmap made from a SVG file, the Item gets made no problem, but the Pixmap doesn't load so there is no image just the item in the scene. The thing that confuses me is that this only happens when I am running it on a different computer than the one that built the exe. When I run the exe on the computer that built it the program works perfectly. Even when I try to run it on a computer with all the required python components and pyqt components installed on the computer, if it isn't the computer that built it, the pixmap is not loaded from the svg file. I am not sure if this is a problem with my cx_freeze setup.py file or if I need to change something in the main code so any help or just pointing me in the right direction will be great. My feeling is that something is getting messed up when cx_freeze is building it so I will paste the contents of my setup.py file below. Also I am running on Windows using Python v3.1.

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')])

PS. Here is my file hierarchy(if that helps at all):

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a nasty problem I have run into myself in the past. Let me quote http://www.py2exe.org/index.cgi/Py2exeAndPyQt: (I know you are using cx_freeze but I am sure you can adapt your script)

PyQt4 and image loading (JPG, GIF, etc)

PyQt4 uses plugins to read those image formats, so you'll need to copy the folder PyQt4pluginsimageformats to appdirimageformats. Like in the above cases, you can use data_files for this. This won't work with bundle_files on.

If the plugins are not reachable, then QPixmap.load/loadFromData will return False when loading an image in those formats.

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_())

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')])

I created this test app on a Windows 7 machine and copied it over to a Windows XP machine. I did not have to copy any dlls around - it worked just like that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...