PyInstaller: "No module named Tkinter" PyInstaller: "No module named Tkinter" tkinter tkinter

PyInstaller: "No module named Tkinter"


Check https://github.com/pyinstaller/pyinstaller/issues/1584. There is an issue with the PIL hook, which excludes the tkinter module.

One solution is to modify the hook file hook-PIL.py located in YourPythonFolder\Lib\site-packages\PyInstaller\hooks by removing the modname_tkinter from excludedimports.

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

from PIL import ImageTkimport Tkinter as tk


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

quote from issue 1877 "It looks like the hook-_tkinter.py is not able to handle custom compiled Tk."Possible workaround: "Thanks, after installed tkinter, tix, tcl-devel and tk-devel using yum installation, It's now work fine. "

Otherwise, Py2exe is also an option for creating a .exe file, and i have used it plenty of times with tkinter with no issues.


I had an extension to this problem. Including Tkinter in the list of hiddenimports enabled me to display plots but I could not save them. By adding FileDialog, tkFileDialog and tkMessageBox into hidden imports in my spec file solved the problem. That is, hiddenimports=['FileDialog', 'Tkinter', 'tkFileDialog', 'tkMessageBox', ]

Angus