2017-07-30 72 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