python 2.7 - How can I save .jpg file from my .exe (PyQt4 Python2.7 py2exe)? -
i'm having problem program, i'm working pyqt4 , python2.7 , used py2exe create .exe
the problem it's screenshot programs it's supose create not being save in directory or anyother way.
this it's setup.py
from distutils.core import setup import py2exe setup(windows=['capture.py'], options={"py2exe": {"includes": ["sip", "pyqt4.qtgui", "pyqt4.qtcore"]}})
and it's capture.py
import os import datetime import time import sys pyqt4 import qtcore pyqt4.qtgui import * class capturescreenshoot (qtcore.qthread): def __init__(self): qtcore.qthread.__init__(self, parent=app) self.count_time = 0 self.complete_path = "" self.signal = qtcore.signal("signal") self.signal_cap = qtcore.signal("signal") def run(self): while true: = datetime.datetime.now() date = str(now.strftime("%y_%m_%d_%h_%m_%s")) currentpath = qtcore.qdir.homepath() + os.sep + "perfq_id_29" + os.sep dire = qtcore.qdir() if not dire.exists(currentpath): dire.mkpath(currentpath) filename = "perfq29_" + date + ".jpg" self.complete_path = currentpath + filename self.emit(self.signal_cap, self.complete_path) #p = qpixmap.grabwindow(qapplication.desktop().winid()) #print p.save(complete_path, 'jpg') self.count_time = self.count_time + 1 self.emit(self.signal, self.count_time) time.sleep(10) class capturetest(qwidget): def __init__(self): qwidget.__init__(self) self.setwindowtitle("modulo de captura de pantalla") self.move(500, 250) vbox = qvboxlayout(self) self.boton = qpushbutton("start thread", self) self.label = qlabel("") self.label.hide() vbox.addwidget(self.boton) vbox.addwidget(self.label) self.boton.clicked.connect(self.call) def call(self): cap = capturescreenshoot() self.connect(cap, cap.signal_cap, self.picture) self.connect(cap, cap.signal, self.timer) cap.start() def timer(self, count): self.label.settext("se han tomado <b> %s </b> capturas" % str(count)) self.label.show() def picture(self, path): p = qpixmap.grabwindow(qapplication.desktop().winid()) p.save(str(path), 'jpg') app = qapplication(sys.argv) w = capturetest() w.show() sys.exit(app.exec_())
i think problem exe cannot find imageformats
plugins directory @ run time. pyqt in interpreter can, exe cannot.
the simplest solution copy directory pyqt (something python27\lib\site-packages\pyqt4\plugins\imageformats
) somewhere in same directory executable. make sure it's called imageformats
there.
not sure of precise directories - use pyside, think it's similar.
i setup.py copying with
ifpath = os.path.join(sys.prefix,"lib","site-packages","pyside","plugins","imageformats") distutils.dir_util.copy_tree(ifpath,dist_dir)
Comments
Post a Comment