cx_freeze Tkinter'找不到模块' [英] cx_freeze Tkinter 'Module not Found'

查看:49
本文介绍了cx_freeze Tkinter'找不到模块'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的python脚本创建可执行文件.我正在使用Windows 7,cx_freeze 5.0.2和Python 3.6.

I am trying to create an executable from my python scripts. I am using Windows 7, cx_freeze 5.0.2 and Python 3.6.

我知道Tkinter不包含在普通库中,您需要添加类似于以下两行的内容:

I know Tkinter isn't included in the normal libraries and that you need to add something similar to the following 2 lines:

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中找到它们的目录

Except of course for 3.6 and in my location, however I can't find their directory in Anaconda 3.6

我创建了一个名为setup.py的文件

I create the following file called 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行运行它.

and run it from the cmd line with python setup.py bdist_msi.

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

It successfully creates the dist which then successfully installs.

但是,当我随后运行.exe时,会出现以下错误:

However when I then run the .exe the following error occurs:

ModuleNotFoundError: no module named 'tkinter'

在此先感谢您的帮助

推荐答案

在第三行添加,"includes":["tkinter"]

会自动检测到依赖关系,但可能需要进行微调.

Dependencies are automatically detected, but it might need fine tuning.

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)])

这篇关于cx_freeze Tkinter'找不到模块'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆