2017-07-30 63 views
0

我正嘗試使用cx_freeze庫從我的python腳本構建一個exe文件。這是我的代碼:cx_freeze中的TCL_LIBRARY

import easygui 
easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No')) 

,這是我的設置代碼:

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 
    ) 

,然後我得到這個錯誤:在編譯時你必須

File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 485, in _LoadPackage 
    self._LoadModule(name, fp, path, info, deferredImports, parent) 
    File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 463, in _LoadModule 
    self._RunHook("load", module.name, module) 
    File "C:\Python36\lib\site-packages\cx_Freeze\finder.py", line 536, in _RunHook 
    method(self, *args) 
    File "C:\Python36\lib\site-packages\cx_Freeze\hooks.py", line 613, in load_tkinter 
    tclSourceDir = os.environ["TCL_LIBRARY"] 
    File "C:\Python36\lib\os.py", line 669, in __getitem__ 
    raise KeyError(key) from None 
KeyError: 'TCL_LIBRARY' 

回答

0

Easygui使用一些Tkinter的這樣包括Tkinter庫。

這應該只是使用include_files arguement的問題

添加以下參數到腳本:

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) 
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6') 
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') 

files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], , "clienticon.ico" ], "packages": ["easygui","matplotlib"]} 

下一個改變:

options = {"build_exe": {"packages":["easygui","matplotlib"]}}, 

到:

options = {"build_exe": files}, 

和一切應該工作。你的腳本現在應該是這樣的:

import cx_Freeze 
import sys 
import matplotlib 

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) 
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6') 
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') 

files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter", "easygui","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": files}, 
    version = "0.01", 
description = "Sea of BTC trading application", 
executables = executables 
) 

。在你的腳本另一個錯誤也是如此。因爲您沒有使用include_files參數來包含要使用的圖標。它不會出現在可執行圖標或輸出中(如果您在tkinterVid28.py文件中使用它)會產生錯誤。

哦,除非你有這樣做的理由,我不明白你爲什麼進口matplotlib。 Cx_Freeze檢測腳本中的導入,您嘗試將其轉換爲可執行文件,而不是在安裝腳本本身中,但將它們列入軟件包始終是個好主意。

我希望這個排序你的問題

+0

@J。 doe請看我更新的答案 – Simon