我正在尝试使用pyinstaller创建PyQt可执行文件。我在Windows 7上使用python 2.7并使用PyCharm。
我正在使用此处的示例代码:https://sukhbinder.wordpress.com/2013/12/16/simple-pyqt-and-matplotlib-example-with-zoompan/
import sys
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import random
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.toolbar.hide()
# Just some button
self.button = QtGui.QPushButton('Plot')
self.button.clicked.connect(self.plot)
self.button1 = QtGui.QPushButton('Zoom')
self.button1.clicked.connect(self.zoom)
self.button2 = QtGui.QPushButton('Pan')
self.button2.clicked.connect(self.pan)
self.button3 = QtGui.QPushButton('Home')
self.button3.clicked.connect(self.home)
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
layout.addWidget(self.button1)
layout.addWidget(self.button2)
layout.addWidget(self.button3)
self.setLayout(layout)
def home(self):
self.toolbar.home()
def zoom(self):
self.toolbar.zoom()
def pan(self):
self.toolbar.pan()
def plot(self):
data = [random.random() for i in range(25)]
ax = self.figure.add_subplot(111)
ax.hold(False)
ax.plot(data, '*-')
self.canvas.draw()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Window()
main.setWindowTitle('Simple QTpy and MatplotLib example with Zoom/Pan')
main.show()
sys.exit(app.exec_())
以下是我在命令行中运行的内容:
pyinstaller.exe --debug --windowed mainUI.py
打开时没有错误。我点击调试过程,但程序没有打开。我的猜测是我需要添加到.spec中,但我不知道要添加什么。
为什么程序打开或出错?