23

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

4

4 回答 4

17

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

更新:在遇到 py2exe 无法“找到”的第三方模块后,我已移至 pyinstaller,如下 kotlet schabowy 建议的那样。两者都有足够的文档并包含可以使用命令行参数运行的 .exe,但我还没有编译 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)
于 2014-11-25T22:09:47.607 回答
9

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

我喜欢将它与Cython一起使用以提高速度。

于 2015-12-18T11:23:44.803 回答
4

您可以使用cx_Freeze这里有一个指南。

于 2013-07-28T10:36:54.517 回答
2

使用Pyinstaller。安装后,在项目所在目录中打开终端。

  1. $ pyinstaller script1.py script2.py ...(其中 script1、script2 等是您项目中使用的所有脚本。)

  2. 命令完成后,打开dist文件夹,进入子目录。在那里你会找到一个可执行文件。

希望能帮助到你。

于 2017-11-12T17:58:35.517 回答