使用cx_freeze打包pyqt4程序为exe
作者:小鱼的互联网观察 发布时间:June 23, 2011 分类:技术
pyQt源程序exam1.py:
#!/usr/bin/env python
import sys,sip !!sip是Qt要求的,必须加
from pyQt4 import QtGui,QtCore
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setFixedSize(200, 120)
self.quit = QtGui.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(self.quit, QtCore.SIGNAL("clicked()"),
QtGui.qApp, QtCore.SLOT("quit()"))
app = QtGui.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
打包命令:
D:\liusp\study\pyQT\exams>d:\cx_Freeze-3.0.3\FreezePython.exe
--shared-lib-name=d:\Python25\lib\site-packages\PyQt4\QtCore4.dll
--shared-lib-name=d:\Python25\lib\site-packages\PyQt4\QtGui4.dll
--shared-lib-name=d:\python25\lib\site-packages\PyQt4\mingwm10.dll
--install-dir dist exam1.py
这三个dll都是PyQt运行时需用到的,最后一行指定打包输出目录。
打包完成后得到dist目录,其包含如下文件:
exam1.exe mingwm10.dll PyQt.QtCore.pyd PyQt4.QtGui.pyd python25.dll QtCore4.dll QtCore4.dll sip.pyd