Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter module not found when launching .exe #567

Closed
nachovoss opened this issue Jan 24, 2020 · 7 comments
Closed

Tkinter module not found when launching .exe #567

nachovoss opened this issue Jan 24, 2020 · 7 comments
Assignees

Comments

@nachovoss
Copy link

A while ago I created a tkinter application that worked fine and compiled with no problems with cx_freeze and worked perfectly.
Today I'm trying to compile another GUI application and it seems to freeze fine(no errors while compiling), but when I execute the .EXE file it says the folowing:
Capture

hope someone can help!
thanks!

@nachovoss
Copy link
Author

Fixed by accessing lib folder from dist folder and changing name Tkinter for tkinter

@marcelotduarte
Copy link
Owner

What version of cx-freeze?
If you try the sample:
https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter
what happens?

@AceScottie
Copy link

AceScottie commented Jan 28, 2020

Im having the same issue.
cx_freeze 6.1 installed using pip.
My main project builds with the folder called Tkinter and simply changing it to tkinter fixes the issue.
Issue persistent in 3.7.6 and 3.8.1.
Tested using the setup sample and the issue is not happening there.
I have tried switching from root.mainloop() to a while loop to recreate closely to my project but no difference
However i believe the root issue is with tkcalendar.
added to simpleTkApp:
from tkcalendar import Calendar, DateEntry
DateEntry(root).pack()

And it now changes to Tkinter.

Worth taking a look ?

Edit: I have had a lot of issue with Babel in my new env so it might stem from there as tkcalendar has it as a dependency.
Errors:
Bad Magic Numbers (this seemed to stop happening randomly)
locale-data not found (recompiled from github and ran additional setup command)
bable.numbers not found (skipped compile so had to "include" it in the options.

@marcelotduarte
Copy link
Owner

@AceScottie
In py3x the correct name is tkinter, in old python the name is Tkinter. Maybe the imported tkcalendar was trying to import Tkinter first and confuses cx-freeze.
Try to put a import tkinter before the import tkcalendar, remove the build dir and rebuild.
If you bad magic number errors, try to uninstall the package and install again.

@AceScottie
Copy link

@marcelotduarte
I have checked thorough tkcalendar and it has an exception to import Tkinter but always as the second option.

try: import tkinter as tk from tkinter import ttk except ImportError: import Tkinter as tk import ttk

And i had the same in my code however i though this might of been an issue so removed the unused import and it didnt change anything.
In the example code provided i added the import below tkinter import so it should be easy to reproduce.

@marcelotduarte
Copy link
Owner

marcelotduarte commented Jan 30, 2020

@nachovoss @AceScottie I confirmed the issue. You can use a workaround while my PR was not merged.
I made this patch on the sample to test:

diff --git a/cx_Freeze/samples/Tkinter/SimpleTkApp.py b/cx_Freeze/samples/Tkinter/SimpleTkApp.py
index ebb0d41..ff73944 100644
--- a/cx_Freeze/samples/Tkinter/SimpleTkApp.py
+++ b/cx_Freeze/samples/Tkinter/SimpleTkApp.py
@@ -1,6 +1,8 @@
 from tkinter import Tk, Label, Button, BOTTOM
+from tkcalendar import Calendar, DateEntry
 
 root = Tk()
+DateEntry(root).pack()
 root.title('Button')
 Label(text='I am a button').pack(pady=15)
 Button(text='Button').pack(side=BOTTOM)
diff --git a/cx_Freeze/samples/Tkinter/setup.py b/cx_Freeze/samples/Tkinter/setup.py
index ed00562..491496d 100644
--- a/cx_Freeze/samples/Tkinter/setup.py
+++ b/cx_Freeze/samples/Tkinter/setup.py
@@ -18,6 +18,14 @@ base = None
 if sys.platform == 'win32':
     base = 'Win32GUI'
 
+options = {
+    'build_exe': {
+        'packages': ['babel'],
+        'excludes': ['Tkinter'],
+        'silent': True
+    }
+}
+
 executables = [
     Executable('SimpleTkApp.py', base=base)
 ]
@@ -25,5 +33,6 @@ executables = [
 setup(name='simple_Tkinter',
       version='0.1',
       description='Sample cx_Freeze Tkinter script',
-      executables=executables
+      executables=executables,
+      options=options
       )

@marcelotduarte
Copy link
Owner

PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants