tkinter – How do I compile my Python 3 app to an .exe?

tkinter – How do I compile my Python 3 app to an .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.

UPDATE: After encountering third-party modules that py2exe had trouble finding, Ive 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 isnt able to handle without debugging or head-scratching.

Heres 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=rC:Python34Scriptspyinstaller.exe,ico=rC:my iconsfavicon.ico,noconsole=False):
    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())

I have found PyInstaller to work the best.
You have many options for example you can pack everything to a one file exe.

I love to use it together with Cython for speed.

tkinter – How do I compile my Python 3 app to an .exe?

You can use cx_Freeze. There is a guide here.

Leave a Reply

Your email address will not be published.