cx_freeze Error: Module not found tkinter

Viewed 408

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.

Here is my code:

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

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


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

cx_freeze error

2 Answers

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

  • in /lib folder of my build i had "Tkinter" folder, renaming it to "tkinter" solved the above issue
  • any following errors of the type module not found could be solved by either adding them to the "includes" tag of build options or finding and copying the whole module folder yourself from python installation folder

The folder name in project must be "lib/tkinter", but maybe it is "lib/Tkinter", then you must rename the folder from "Tkinter" to "tkinter".

Related