如何将我的Python 3应用程序编译为.exe?

Sam*_*ine 22 python exe compilation tkinter python-3.3

如何将我的Python应用程序转换为.exe?我制作了一个程序,tkinter并想知道如何让其他人使用它.我使用Python 3.3.我搜索了一下但找不到任何东西.

gss*_*gss 15

cx_Freeze执行此操作但创建了一个包含大量依赖项的文件夹.py2exe现在这样做,并且使用--bundle-files 0选项,只创建一个EXE,这可能是您问题的最佳解决方案.

更新:在遇到第三方模块后,py2exe无法"查找",我已经转移到pyinstaller,因为kotlet schabowy建议如下.两者都有足够的文档,包括可以使用命令行参数运行的.exes,但是我还没有编译pyinstaller无法在没有调试或头痛的情况下处理的脚本.

这是一个简单的便利函数,我用它来构建一个.exe,我的默认值来自解释器(当然批量或类似的也可以):

import subprocess,os
def exe(pyfile,dest="",creator=r"C:\Python34\Scripts\pyinstaller.exe",ico=r"C:\my icons\favicon.ico",noconsole=False):
    insert=""
    if dest: insert+='--distpath ""'.format(dest)
    else: insert+='--distpath "" '.format(os.path.split(pyfile)[0])
    if ico: insert+=' --icon="{}" '.format(ico)
    if noconsole: insert+=' --noconsole '
    runstring='"{creator}" "{pyfile}" {insert} -F'.format(**locals())
    subprocess.check_output(runstring)
Run Code Online (Sandbox Code Playgroud)

  • 这回答"什么?",但不是"如何?" (4认同)

kot*_*owy 9

我发现PyInstaller工作得最好.您有很多选项,例如您可以将所有内容打包到一个文件exe.

我喜欢和Cython一起使用它来提高速度.