创建 python 脚本以执行

create python script to exe

我正在尝试使用 cv_freeze 库来创建我的 python 脚本来执行 GUI 应用程序。我的应用程序仅使用 tkinter,但是当我尝试构建 exe 文件时:我收到 TCL_LIBRARY 错误。这是为什么?这是我的设置代码:

import cx_Freeze
import sys
import matplotlib

base = None

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

executables = [cx_Freeze.Executable("tkinterVid28.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "SeaofBTC-Client",
    options = {"build_exe": {"packages":["easygui","matplotlib"]}},
    version = "0.01",
    description = "Sea of BTC trading application",
    executables = executables
    )

这是 myGUI python 代码:

import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()

我在 python 3.6 中使用, 感谢您提供帮助或不提供帮助。

将此放在 cx_Freeze setup.py 代码的前两行之前。

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tk8.6'

将路径替换为正确的 python 路径。如果你的 python 路径是 C:\Python36-19 那么你会想要做

os.environ['TCL_LIBRARY'] = r'C:\Python36-19\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python36-19\tcl\tk8.6'

如果您在查找 Python 路径时需要帮助,请告诉我。在 windows(我认为是 linux)中,您可以 运行 where python 并且您想使用到达 PythonXX-XX 文件夹的路径然后做 \tcl\tcl8.6\tcl\tk8.6