如何将我的 Python 3 应用程序编译为 .exe? [英] How do I compile my Python 3 app to an .exe?

查看:33
本文介绍了如何将我的 Python 3 应用程序编译为 .exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I convert my Python app to a .exe? I made a program with tkinter and was wondering how to make it possible for others to use. I use Python 3.3. I searched for a bit but could not find anything.

推荐答案

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

cx_Freeze does this but creates a folder with lots of dependencies. py2exe now does this and, with the --bundle-files 0 option, creates just one EXE, which is probably the best solution to your question.

更新:在遇到 py2exe 无法找到"的第三方模块后,我已按照下面的 kotlet schabowy 建议转移到 pyinstaller.两者都有丰富的文档,并包含您可以使用命令行参数运行的 .exe,但我还没有编译一个脚本,pyinstaller 在没有调试或头疼的情况下无法处理.

UPDATE: After encountering third-party modules that py2exe had trouble "finding", I've moved to pyinstaller as kotlet schabowy suggests below. Both have ample documentation and include .exes you can run with command line parameters, but I have yet to compile a script that pyinstaller isn't able to handle without debugging or head-scratching.

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

Here's a simple convenience function I use to build an .exe with my defaults from the interpreter (of course a batch or similar would be fine too):

import subprocess,os
def exe(pyfile,dest="",creator=r"C:Python34Scriptspyinstaller.exe",ico=r"C:my iconsfavicon.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)

这篇关于如何将我的 Python 3 应用程序编译为 .exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆