我在python文件中使用了cv2包。在通过py2exe将文件转换为exe文件之前,它可以工作。但是当转换exe文件时,我得到运行时错误!此应用程序已请求Runtime以不寻常的方式终止它。这是我的档案。 test1.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_())
test2.py
import numpy as np
import cv2
from cv2 import cvtColor
class opencv_test:
def change(self,filename):
print filename
img = cv2.imread(filename)
img = cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.imwrite("C:\\pythontest\\certphoto\\output\\what.jpg",img)
转换为exe文件setup.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}
)
错误消息: