Pyinstaller and Tkinter

I created a Python application (2.7) that uses Tkinter and am trying to create Windows7.exe using Pyinstaller (3.2). The application works on Windows, I run it as python myapp.py , but after compiling into the pyinstaller distribution, I get this error message:

 ImportError: No module named Tkinter 

To make sure myapp.py top contains:

 from copy import deepcopy import cPickle as pickle import Tkinter as tk from PIL import ImageTk 

Checking the distribution directory, I see tk85.dll, tcl85.dll and two directories that see the corresponding ones, tcl / and tk /

I found many links to Tkinter secondary dependencies, such as matplotlib, which imports Tkinter itslef, but I did not find any details about such a direct dependency.

Any ideas on how to make this work?

+5
source share
2 answers

Check out https://github.com/pyinstaller/pyinstaller/issues/1584 . There was a problem with the PIL hook, which excludes the tkinter module.

One solution is to modify the hook -PIL.py file of the hook file located in the YourPythonFolder \ Lib \ site-packages \ PyInstaller \ hooks folder , removing modname_tkinter from the excluded import.

Or just change the order of the import statements in the code. At:

 from PIL import ImageTk import Tkinter as tk 
+2
source

Have you checked: https://github.com/pyinstaller/pyinstaller/issues/1877 (or other problems)? https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong

quote from number 1877 "It seems that hook-_tkinter.py is not able to handle custom compiled Tk." Possible workaround: "Thank you, after installing tkinter, tix, tcl-devel and tk-devel using the yum installation, it now works fine."

Otherwise, Py2exe is also an option to create the .exe file, and I have used it many times with tkinter without any problems.

0
source

All Articles