2017-07-29 33 views
0

我想将我的python脚本转换为exe文件 ,任何人都可以从任何计算机上运行它,包括没有python的计算机。 所以我看到一些指南解释最好的方法是在cx_freeze库中使用。 ,所以我建立了一个只在Tkinter的使用小的GUI应用程序,这是我的代码:使用cx_freeze构建python脚本以执行文件

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

,这是我的安装文件:

from cx_Freeze import setup, Executable 
setup(
    name="GUI PROGRAM", 
    version="0.1", 
    description="MyEXE", 
    executables=[Executable("try.py", base="Win32GUI")], 
    ) 

,并运行此命令:

python setup.py build 

然后我得到这个错误:

KeyError: 'TCL_LIBRARY 

它只发生在我使用tkinter。所以我想我错过了一些东西,我需要以某种方式添加tkinter到安装文件。 有人可以帮助我吗? 非常感谢你们。

+0

你使用的是什么版本的python?我建议pyinstaller作为一个包来exe文件...它非常易于使用 –

+0

我在python 3.6中使用,我尝试了它们,它们非常复杂 –

+0

没有Cx_Freeze那么难,我可以确保你。 – Simon

回答

0

尝试你改变你的安装脚本,以这样的:

from cx_Freeze import setup, Executable 
import os 
import sys 
import os.path 

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"]} 

setup(
    name="GUI PROGRAM", 
    version="0.1", 
    description="MyEXE", 
    options = {"build_exe": files}, 
    executables=[Executable("try.py", base="Win32GUI")], 
) 

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"]}将包括Tk的缺失和Tcl运行时间。

+0

@Mark green这是我更新的答案,如果你还没有看到它。 – Simon

相关问题