0

I wrote the folowwing at the top of my script:

try:
    from Tkinter import *
    from Tkinter import messagebox
except ModuleNotFoundError:
    from tkinter import *
    from tkinter import messagebox
else:
    print("tkinter error")
    input()
    sys.exit()

Running my script as .py or .pyw works without problems. But when I make and .exe out of it with cx_Freeze, the exe throws the error:

enter image description here

And why is that? how to solve this?

Thanks...

EDIT: Also my setup.py:

import sys
import os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = r"C:\Python\Python36-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Python\Python36-32\tcl\tk8.6"

base = None


executables = [Executable("toolbar.py", base=base)]

packages = []
options = {
    'build_exe': {

        'packages':packages,
    },

}

setup(
    name = "Desktop Toolbar",
    options = options,
    version = "1.0",
    description = " ",
    executables = executables
)
mbilal25tr
  • 131
  • 1
  • 10
  • Did you include `tkinter` when compiling? – Ethan Field Sep 18 '17 at 13:39
  • @Ethan Field How do I do that? I'm not very experienced with cx_Freeze – mbilal25tr Sep 18 '17 at 13:49
  • Neither am I, but if it's stating `Module not found` I would assume this is because the module was not found. – Ethan Field Sep 18 '17 at 13:54
  • Try following this https://stackoverflow.com/questions/42323533/when-using-cx-freeze-and-tkinter-i-get-dll-load-failed-the-specified-module-c – Ethan Field Sep 18 '17 at 13:54
  • @Ethan Field I have done everything needed in the link you gave. But my error is not at compiling. It's when I run the .exe file I get. – mbilal25tr Sep 18 '17 at 14:06
  • Apologies, wrong technical word. So you followed the steps given in that answer and you still have the same problems? Have you tried using a fresh `virtualenv` install and running cx_Freeze from there? – Ethan Field Sep 18 '17 at 14:09
  • @EthanField How do you mean running cx_Freeze from virtualenv? – mbilal25tr Sep 18 '17 at 14:15
  • Create a fresh `virtualenv` (http://docs.python-guide.org/en/latest/dev/virtualenvs/) with only the modules you need and your script and try to compile that with cx_Freeze (https://stackoverflow.com/questions/40014823/compile-python-virtual-environment) – Ethan Field Sep 18 '17 at 14:26

0 Answers0