cx_freeze Error: Module not found tkinter
cx_freeze Error: Module not found tkinter
我开始遇到 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 已经有一段时间了,但我从未见过这个错误。
我遇到了和你一样的问题,经过长时间的故障排除后我发现
- 在我构建的 /lib 文件夹中我有 "Tkinter" 文件夹,将其重命名为 "tkinter" 解决了上述问题
- 任何以下未找到模块类型的错误都可以通过将它们添加到构建选项的 "includes" 标签或从 python 安装文件夹中自己查找并复制整个模块文件夹来解决
项目中的文件夹名称必须是"lib/tkinter",但也可能是"lib/Tkinter" ],则必须将文件夹从“Tkinter”重命名为“tkinter”。
我开始遇到 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 已经有一段时间了,但我从未见过这个错误。
我遇到了和你一样的问题,经过长时间的故障排除后我发现
- 在我构建的 /lib 文件夹中我有 "Tkinter" 文件夹,将其重命名为 "tkinter" 解决了上述问题
- 任何以下未找到模块类型的错误都可以通过将它们添加到构建选项的 "includes" 标签或从 python 安装文件夹中自己查找并复制整个模块文件夹来解决
项目中的文件夹名称必须是"lib/tkinter",但也可能是"lib/Tkinter" ],则必须将文件夹从“Tkinter”重命名为“tkinter”。