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

51,788

Solution 1

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", 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.

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:\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)

Solution 2

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.

Solution 3

You can use cx_Freeze. There is a guide here.

Share:
51,788

Related videos on Youtube

Meers E. Chahine
Author by

Meers E. Chahine

I'm Meers, who are you? http://go.billbandits.com/meers

Updated on July 02, 2020

Comments

  • Meers E. Chahine
    Meers E. Chahine almost 4 years

    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.

    • Meers E. Chahine
      Meers E. Chahine over 10 years
      yes, but they are all for 2.7 and below, i use 3.3
    • Andy G
      Andy G over 10 years
      I added the 3 to your title but, unfortunately, I suspect your question still might get closed. Good luck.
  • CaffeineConnoisseur
    CaffeineConnoisseur about 8 years
    This answers "What?", but not "How?"
  • Folkert van Heusden
    Folkert van Heusden over 4 years
    Maybe add an example for both suggestions?

Related