python程序编译成exe文件

最近越来越喜欢使用python写工具。使用的时候,发现程序内部成员python安装目录常常不同,如果用bat双击执行,常常需要修改从svn上down下来的bat文件中python.exe的路径。而给策划、美术或者QA使用,更是需要让他们安装python和各种插件,他们能把你烦死。所以,必须把py文件转成exe文件,然后做到傻瓜式的双击执行。 我了解到有两个常用的套件:py2exe和pyinstaller,我选用的是pyinstaller。这里记录一下使用方法。 一、首先,上官网下载,http://www.pyinstaller.org/,推荐32位2.7版本的,然后解压。 二、使用方法     doc/Manual.html里写的很详细,这里简单说一下最基本、常用的功能。     1. cmd下进入解压的pyinstaller目录,执行命令格式如下:         python pyinstaller.py [opts] program.py                 几个常用选项包括:         -D, --onedir  创建一个目录,包含exe文件和依赖文件,这是默认选项。(Create a folder name containing an executable name and all support files. This is the default.)         -F, --onefile 创建一个exe文件,所有依赖文件都打包进了这个exe文件,这个exe会比较大,但是我觉得方便使用。(Create a single executable file name (or name .exe or name .app).)          -c, --console, --nowindowed 控制台,无界面,默认选项。(Set up a console subsystem for standard input/output at run time. This is the default for both one-file and one-folder modes.)          -w, --windowed, --noconsole 窗口无控制台。(On Windows and Mac OS X, do not create a console window at run time for standard input/output. (This option is ignored for other operating systems.) On Mac OS X, this option triggers the creation of an OS X application bundle.)          比如:D:\soft\python\PyInstaller-2.1>python pyinstaller.py -c -F E:\work\unity\xxx\trunk\tools\excel2json\excel2json.py     报错,依赖pywin32     2. 安装pywin32。http://sourceforge.net/projects/pywin32/files/pywin32/,下载后双击安装即可。     3. 再次cmd下执行,D:\soft\python\PyInstaller-2.1>python pyinstaller.py -c -F E:\work\unity\xxx\trunk\tools\excel2json\excel2json.py。                  成功生成exe!

猜你喜欢

转载自www.cnblogs.com/cxcjhk/p/11701387.html