将PyQt项目转化为WIN下的可执行程序
对于这个问题,自己也尝试了不少的安装方法,现将成功的一条记录如下,供参考。
1.先下载与安装:Microsoft Visual C++ 2008 Redistributable Package (x86),从这里:http://www.microsoft.com/DOWNLOADS/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
或者将msvcp90.dll直接放到如下目录内:C:\Python26\DLLs。
2.写一个最简单的例子如下,命名为:test.py
"""
This is a template for PyQt4 Pragram based QDialog
"""
from PyQt4 import QtGui
from PyQt4 import QtCore
import sys
class Form(QtGui.QDialog):
def __init__(self, parent = None):
super(Form, self).__init__(parent)
#~ layout = QtGui.QVBoxLayout()
#~ self.setLayout(layout)
def main():
"""
The Pragram main port
"""
app = QtGui.QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
if __name__ == '__main__':
main()
3.写一个安装脚本如下,命名为:setup.py
from distutils.core import setup
import py2exe
import sys
# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("--includes")
sys.argv.append("sip")
class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources
self.version = "0.5.0"
self.company_name = "No Company"
self.copyright = "no copyright"
self.name = "py2exe sample files"
test = Target(
# used for the versioninfo resource
description = "A sample GUI app",
# what to build
script = "test.py",
#~ other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="test_wx"))],
icon_resources = [(1, "editra.ico")]
#~ dest_base = "test_wx"
)
setup(
# The first three parameters are not required, if at least a
# 'version' is given, then a versioninfo resource is built from
# them and added to the executables.
#~ version = "0.5.0",
#~ description = "py2exe sample script",
#~ name = "py2exe samples",
# targets to build
windows = [test]
#~ console = ["hello.py"],
)
4.执行你的setup.py脚本,看是否生成了你想要的东西。
据说(我没有测试)发布是不要忘记了文件:msvcp90.dll。