Python cx\U冻结错误:找不到模块tkinter

Python cx\U冻结错误:找不到模块tkinter,python,tkinter,cx-freeze,Python,Tkinter,Cx Freeze,我开始对miniconda和PyCharm有一些问题,所以我不得不重新安装它们。但是,现在当我使用cx_freeze创建.exe时,我得到以下错误 这是我的密码: from tkinter import * from tkinter import ttk from ttkthemes import ThemedTk from ttkthemes import themed_tk as tk import os from tkinter import messagebox import getpa

我开始对miniconda和PyCharm有一些问题,所以我不得不重新安装它们。但是,现在当我使用cx_freeze创建.exe时,我得到以下错误

这是我的密码:

from tkinter import *
from tkinter import ttk
from ttkthemes import ThemedTk
from ttkthemes import themed_tk as tk
import os
from tkinter import messagebox
import getpass
import pyodbc
import test
import time



class Application(object):
    def __init__(self,master):
        self.master=master

        self.itemIn = ttk.Button(master, text="In", width=35,
                                 command=self.itemIn).grid(row=2, column=0, padx=10,pady=15)
        self.itemOut = ttk.Button(master, text="Out", width=35,
                                       command=self.itemOut).grid(row=3, column=0, padx=10)

    def itemIn(self):
        pass
    def itemOut(self):
        pass

def main():
    global userList
    strForDB = os.getcwd() + '\DBINFO.txt'
    openDBFile = open(strForDB, 'r')
    currentDirForDB = openDBFile.read()
    openDBFile.close()
    dbPath = currentDirForDB
    conToSubmit = pyodbc.connect(dbPath)
    curToSubmit = conToSubmit.cursor()
    userName = getpass.getuser()

    root = tk.ThemedTk()
    root.get_themes()
    root.set_theme("radiance")
    app=Application(root)
    root.title("Main Menu v:5.1")
    root.configure(background="#F4F3F1")
    root.resizable(0, 0)
    # Change Application Icon with below:
    root.wm_iconbitmap(os.getcwd()+'/Z Logo.ico')
    ### To maximize
    # w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    # root.geometry("%dx%d+0+0" % (w, h))
    root.geometry('340x510+300+80')
    root.mainloop()
    #else:
    #    messagebox.showerror("Access Denied", "You are not allowed to access this application.")
    #    return


if __name__=='__main__':
    main()
这是cx_冻结构建脚本,我在其中导入了所有相关模块

import cx_Freeze
import os
from cx_Freeze import *
import sys
if sys.platform == "win32":
     base = "Win32GUI"

imodules=['tkinter','pyodbc','getpass','pathlib','openpyxl','datetime','os','win32print','win32ui'] #modules to include

emodules=[] ###modules to NOT include
            #(useful if a module is forcefully installed
            #even if you don't want that module)



build_exe_options={"packages":imodules,"excludes":emodules}

setup(
        name= "WMS System",
        options={"build_exe":build_exe_options},description="App to track Inventory",author="VM",
        executables=[
        Executable(
                 "WMS.py", base=base, icon="Z logo.ico"
                )
            ]
        )


我已经使用cx_freeze很长一段时间了,但我从未见过这个错误


我遇到了与您相同的问题,经过长时间的故障排除,我发现

  • 在我构建的/lib文件夹中,我有一个“Tkinter”文件夹,将其重命名为“Tkinter”解决了上述问题
  • 以下未找到模块类型的任何错误都可以通过将它们添加到构建选项的“includes”标记或自己从python安装文件夹中查找并复制整个模块文件夹来解决

项目中的文件夹名称必须是“lib/tkinter”,但可能是“lib/tkinter”,然后您必须将文件夹从“tkinter”重命名为“tkinter”。

您可以向我们展示您的cx\u冻结构建脚本吗?我看到您正在使用anaconda;那对tkinter有什么不同吗?你认为你的cx\u freeze脚本中的
\u tkinter
tkinter
会有帮助吗?我会试试。我还发现Anaconda不识别tkinter的import*。这不起作用。有什么理由将其命名为“tkinter”?我打赌cx_freeze会在复制时更改它,因为在python库文件夹中只有“tkinter”。这很奇怪。我的一个应用程序没有这样做,exe运行正常。但是,在我的另一个使用相同python版本的应用程序上,由于某种原因,安装程序将文件夹命名为大写字母T。这会在我这方面导致相同的问题。