cx_freeze错误:找不到模块tkinter

问题描述 投票:0回答:1

我开始遇到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_freeze构建脚本,我已经在其中导入了所有相关模块。

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已有一段时间了,但是我从未见过此错误。

cx_freeze error

python tkinter cx-freeze
1个回答
0
投票

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

  • 在我的构建的/ lib文件夹中,我有“ Tkinter”文件夹,将其重命名为“ tkinter”解决了以上问题
  • 未找到类型模块的以下任何错误均可通过将它们添加到构建选项的“ includes”标签中,或者自己从python安装文件夹中查找并复制整个模块文件夹来解决
© www.soinside.com 2019 - 2024. All rights reserved.