2017-07-31 130 views
0

我想在cv_freeze库中使用创建我的python脚本来exe应用程序。我的应用程序只使用tkinter,但是当我尝试构建exe文件时:出现TCL_LIBRARY错误。这是为什么?这是我的设置代码:创建python脚本为exe

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, 感谢帮助或没有帮助。

回答

0

将此放在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那么如果您需要帮助找到你的Python路径,让我知道你会想这样做

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

。在Windows中(我认为Linux),你可以运行where python,你想使用PythonXX-XX文件夹的路径,然后做\tcl\tcl8.6\tcl\tk8.6

+0

它现在生成的exe文件。但我得到这个错误,当我打开exe文件:http://i.imgur.com/v2YMpBN.png – odri

+0

@odri试试这个https://stackoverflow.com/questions/43568915/import-tkinter-if-this-失败,您的python可能不会被配置为tk – James

+0

感谢现在的工作。非常感谢! – odri