pydata

Keep Looking, Don't Settle

Tkinter to exe file with cx_freeze

cx_freeze用来把python code打包成为windows的可执行文件(exe文件)

首先下载安装cx_freeze(google或者youtube)各种资料。

新建一个文件夹,把python code复制到这个文件夹。在这个文件夹下面新建一个setup.py文件如下,主要在setup里面列出需要的package。刚开始的时候一直有error,cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys),最后的解决办法是在options加入'excludes': [ 'collections.abc']

然后进入windows cmd,cd到python code和setup.py的文件的文件夹,run python setup.py,run完以后会在当前文件夹下面新建一个build文件夹,所有的东西都在这个build文件夹下面。其中的exe就是可执行文件。

alt text

import cx_Freeze
import sys
import matplotlib

base = None

if sys.platform == 'win32':
   base = "Win32GUI"

executables = [cx_Freeze.Executable("cre_right_sizing_dataprint.py", base=base)]

cx_Freeze.setup(
   name = "WhateverYourNmIs",
   options = {"build_exe": {"packages":["Tkinter",  "pandas", "numpy", "ttk", "os","sys", "collections"], 'excludes': [ 'collections.abc']}},
   version = "0.01",
   description = "CRE Test",
   executables = executables
   )