2012年2月24日星期五

python+pyqt4脚本转exe程序


python+pyqt4脚本转exe程序
转换工具:Py2exe
运行平台:Windows

下面按步骤说明将一个Python脚本转换成exe程序的过程。
1. 安装Py2exe
2. 进入hello.py的目录,编写安装脚本setup.py。其内容如下:

1. 精简版+图标  pyqt4打包
#setup_pyqt.py
#with logo.ico and all the files bundled in one exe

name1=raw_input("Enter the name of py file: ")
from distutils.core import setup
import py2exe

setup(zipfile=None,
      windows=[{"script" : name1, 'icon_resources':[(1, 'logo.ico')]}],
      options={"py2exe" : {"includes" : ["sip"]},"py2exe":   { "bundle_files": 1,"includes" : ["sip"] }})



2. 精简版:打包 python 脚本 成 带图标的exe 程序,无小文件生成

#setup_python.py
#with logo.ico and all the files bundled in one exe

name1=raw_input("Name of py file: ")
from distutils.core import setup
import py2exe
import sys
includes = ["encodings", "encodings.*"]  
sys.argv.append("py2exe")
options = {"py2exe":   { "bundle_files": 1,"includes" : ["sip"] }    }
setup(options = options,
      zipfile=None,
      console = [{"script":name1, 'icon_resources':[(1, 'logo.ico')]}])


3. 打开DOS并切换其工作目录为当前目录,按如下方式在DOS中运行setup_pyqt.py, setup_python.py:

python setup_pyqt.py py2exe
python setup_python.py py2exe