py2exe运行时将pyqt文件转换为exe文件错误:此应用程序已请求运行时以异常方式终止它

2024-05-19 02:30:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python文件中使用了cv2包。在通过py2exe将文件转换为exe文件之前,它可以工作。但是当转换exe文件时,我得到运行时错误!此应用程序已请求运行时以不寻常的方式终止它。这是我的档案。 测试1.py

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from test2 import opencv_test
import os
import sys 

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
class BaseInfo(QWidget):
def __init__(self,parent=None): 
    super(BaseInfo,self).__init__(parent)
    self.filename = "C:\pythontest\certphoto\\test1.png"
    self.imageLabel=QLabel()  
    self.imageLabel.setSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored)  
    image = QPixmap(self)
    if image.load(self.filename):
       pixmap_resized = image.scaled(519, 692, Qt.KeepAspectRatio)
       self.imageLabel.setPixmap(pixmap_resized) 
       self.resize(519,692) 

    hLayout=QHBoxLayout()
    hLayout.addWidget(self.imageLabel)
    OKPushButton=QPushButton(self.tr("change"))   
    bottomLayout=QHBoxLayout()  
    bottomLayout.addStretch() 
    bottomLayout.addWidget(OKPushButton)  
    self.connect(OKPushButton,SIGNAL("clicked()"),self.extpic)

    mainLayout=QGridLayout(self)  
    mainLayout.setMargin(15)  
    mainLayout.setSpacing(10)  
    mainLayout.addLayout(hLayout,0,0)  
    mainLayout.addLayout(bottomLayout,1,0)

def extpic(self):
    cv_test = opencv_test()
    cv_test.change(str(self.filename)) 

if __name__ == "__main__":
app = QApplication(sys.argv)
form=BaseInfo()
form.show()
sys.exit(app.exec_()) 

测试2.py

^{pr2}$

转换为exe文件设置.py在

from distutils.core import setup
import py2exe
import sys

sys.argv.append('py2exe')

py2exe_options = {
     "includes": ["sip","numpy","cv2"],
     "dll_excludes": ["MSVCP90.dll",],
     "compressed": 1,
     "optimize": 2,
     "ascii": 0,
     "bundle_files": 1,
    }

setup(
   name = 'PyQt Demo',
   version = '1.0',
   windows = [r'C:\pythontest\testphoto\test1.py'],
   zipfile = None,
   options = {'py2exe': py2exe_options}
  )

错误消息:

enter image description here


Tags: 文件frompytestimageimportselfsys

热门问题