23

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.

Machavity
  • 28,730
  • 25
  • 78
  • 91
S.E. Chahine
  • 1,166
  • 1
  • 13
  • 38
  • 1
    yes, but they are all for 2.7 and below, i use 3.3 – S.E. Chahine Jul 28 '13 at 10:32
  • Okay, but it is still a very common question. My answer was from a quick Google search. – Andy G Jul 28 '13 at 10:38
  • 1
    I added the 3 to your title but, unfortunately, I suspect your question still might get closed. Good luck. – Andy G Jul 28 '13 at 10:44
  • possible duplicate of [How can I turn a python 3.3 script into executable file? I found PyInstaller and py2exe, but both did not support 3.3](http://stackoverflow.com/questions/16770267/how-can-i-turn-a-python-3-3-script-into-executable-file-i-found-pyinstaller-and) – Cees Timmerman May 19 '15 at 13:52

4 Answers4

16

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)
gss
  • 499
  • 6
  • 8
9

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.

kotlet schabowy
  • 778
  • 1
  • 5
  • 16
4

You can use cx_Freeze. There is a guide here.

Andy G
  • 18,518
  • 5
  • 42
  • 63
1

Use Pyinstaller. After installing it, open terminal in the directory where your project resides.

  1. $ pyinstaller script1.py script2.py ... (where script1, script2, etc. are all the scripts used in your project.)

  2. After command is completed, open dist folder and enter the subdirectory. There you'll find an executable.

Hope it helps.