我正在尝试从我的python脚本创建一个可执行文件。我使用的是Windows 7,cx_freeze 5.0.2和Python 3.6。
我知道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)])
并使用python setup.py bdist_msi
从cmd行运行它。
它成功创建了然后成功安装的dist。
然而,当我运行.exe时,会发生以下错误:
ModuleNotFoundError: no module named 'tkinter'
提前感谢您对此的任何帮助
答案 0 :(得分: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)])