Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller: "No module named Tkinter"

I've built a Python (2.7) app that uses Tkinter and am trying to build a Windows7 .exe using Pyinstaller (3.2). The app works find in windows is I run it as python myapp.py, but once compiled into a pyinstaller distributable, I get this error message:

ImportError: No module named Tkinter

Just to be sure, the top of myapp.py 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 pertinent, tcl/ and tk/

I've found many references to secondary Tkinter dependencies, such as matplotlib which imports Tkinter itslef, but I've not found any details of a direct dependency like this.

Any ideas how to get this one working?

like image 586
KirkD-CO Avatar asked Oct 30 '22 04:10

KirkD-CO


1 Answers

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 ImageTk
import Tkinter as tk
like image 121
Repiklis Avatar answered Nov 02 '22 11:11

Repiklis