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

社会主义新天地 提交于 2019-11-26 12:42:38

问题


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.


回答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)



回答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.




回答3:


You can use cx_Freeze. There is a guide here.




回答4:


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.



来源:https://stackoverflow.com/questions/17907258/how-do-i-compile-my-python-3-app-to-an-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!