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

问题描述

我开始遇到miniconda和PyCharm的一些问题,因此我必须重新安装它们.但是,现在当我使用cx_freeze创建.exe时,出现以下错误.

I started having some issues with miniconda and PyCharm so I had to reinstall them. However, now when I use cx_freeze to create .exe I get the error below.

这是我的代码:

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

This is cx_freeze build script, where I have imported all the relevant modules.

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

I have been using cx_freeze for quite some time but I have never seen this error.

推荐答案

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

I was having identical problem as you and after a long troubleshooting session I found out that

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

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

08-31 09:52