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.
Yes, it is possible to compile Python scripts into standalone executables. PyInstaller can be used to convert Python programs into stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD, Solaris, and AIX. It is one of the recommended converters.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With