2017-07-31 131 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