python程序转成exe可执行程序

    最近越来越喜欢使用python写工具。使用的时候,发现程序内部成员python安装目录常常不同,如果用bat双击执行,常常需要修改从svn上down下来的bat文件中python.exe的路径。而给策划、美术或者QA使用,更是需要让他们安装python和各种插件,他们能把你烦死。所以,必须把py文件转成exe文件,然后做到傻瓜式的双击执行。


    我了解到有两个常用的套件:py2exepyinstaller,我选用的是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!


        

          生成的目标文件在pyinstaller目录下。


    p.s. 后来发现,生成的exe无法在中文路径下执行。在这篇blog中看到了原因,pyinstaller中处理utf8编码的地方有bug,blog的作者把自己修改过的传到了github上,点击打开链接,我测试了32位python2.7可用。

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值