2017-06-12 79 views
0

我想从我的python脚本创建一个可执行文件。我使用Windows 7,cx_freeze 5.0.2和Python 3.6。cx_freeze Tkinter'模块未找到'

我知道Tkinter的不包括在正常的库和你需要类似的东西添加到以下两行:

os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tcl8.6" 
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tk8.6" 

当然除了3.6和我的位置,不过,我可以”找不到Anaconda的3.6

我创建了一个名为setup.py

import sys 
from cx_Freeze import setup, Executable 

# Dependencies are automatically detected, but it might need fine tuning. 
build_exe_options = {"packages": ["os"]} 

# GUI applications require a different base on Windows (the default is for a 
# console application). 
base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 

setup( name = "McCabe-Thiele", 
     version = "0.1", 
     description = "My GUI application!", 
     options = {"build_exe": build_exe_options}, 
     executables = [Executable("GUI.py", base=base)]) 

下列文件,并从CMD符合python setup.py bdist_msi运行它自己的目录。

它成功创建了dist,然后成功安装。

但是当我再运行.exe出现以下错误:

ModuleNotFoundError: no module named 'tkinter' 

感谢您在此先

回答

0

在第三行任何帮助添加,"includes":["tkinter"]

依赖是自动检测到,但它可能需要微调。

build_exe_options = {"packages": ["os"],"includes":["tkinter"]} 

它的工作对我来说,当我和python setup.py build

从问题更新的代码运行:

import sys 
from cx_Freeze import setup, Executable 

# Dependencies are automatically detected, but it might need fine tuning. 
build_exe_options = {"packages": ["os"],"includes":["tkinter"]} 

# GUI applications require a different base on Windows (the default is for a 
# console application). 
base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 

setup( name = "McCabe-Thiele", 
     version = "0.1", 
     description = "My GUI application!", 
     options = {"build_exe": build_exe_options}, 
     executables = [Executable("GUI.py", base=base)])