我怎样将我的Python程序转换成.exe
文件呢?我用tkinter
编写了一个程序,现在想让其他人也能使用。我使用的Python版本是3.3。我查找了一下,但没有找到相关内容。
我怎样将我的Python程序转换成.exe
文件呢?我用tkinter
编写了一个程序,现在想让其他人也能使用。我使用的Python版本是3.3。我查找了一下,但没有找到相关内容。
cx_Freeze可以实现这一点,但是会创建一个有很多依赖文件的文件夹。py2exe现在也可以实现这一点,并且使用--bundle-files 0选项,只会创建一个EXE文件,这可能是您问题的最佳解决方案。
更新:在遇到py2exe难以“找到”的第三方模块后,我已经转向了像kotlet schabowy建议的pyinstaller。两者都有充足的文档,并包括您可以通过命令行参数运行的.exe文件,但我还没有编译过pyinstaller无法处理而需要调试或思考的脚本。
这是一个简单的便利函数,我使用它从解释器中构建一个带有我的默认值的.exe(当然批处理或类似方法也可以):
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)
$ pyinstaller script1.py script2.py ...
(其中script1、script2等是项目中使用的所有脚本)
命令完成后,打开dist
文件夹并进入子目录,您将找到一个可执行文件。