Reputation: 89
Just getting started with Pyinstaller (and somewhat with Tk windowing) and having trouble getting my tkinter windows app (under python 3.5) running successfully. I may be doing something stupid but I've tried everything I know and I really need to get this running, so any help is greatly appreciated. Just a note, all of my code runs fine under normal python 3.5.1 & 3.5.3. Have latest version of PyInstaller installed (3.2.1) and it appears to be running OK.
I switched over to the following simple windowed "Hello World!" app to see if I could get this to work,
from tkinter import *
root = Tk()
root.title("Test Window")
#Setup window widgets and place on window
l1 = Label(root,text='Hello World!',font=("Verdana",18))
l2 = Label(root,text='Hello World!',font=("Times New Roman",9))
b1 = Button(root, text='Button 1', font=("Verdana",12), state=DISABLED)
b1.pack()
b1.place(x=220, y=180)
l1.pack()
l1.place(x=170, y=10)
l2.place(x=200, y=60)
root.mainloop()
but it appears to be having the same issues as my original application.
Maybe it's just because I'm new to PyInstaller but I'm not finding the docs really easy to find specific answers from. But looking a little deeper, I decided to add the -d option to the command line to see the debug output as it tried to execute my app, so the complete command line I'm using is: > pyinstaller -F -w -d c:\PythonApps\Hello.py . That gave me lots of info ending in this error message:
Failed to execute script pyi_rth_tkinter.
This was the same error I saw for my original program. I was able to find 'pyi_rth_tkinter.py' on my system (actually 2 versions of the file), not sure why PyInstaller is having problems executing it. But since that file spits out error messages about path problems for Tcl & Tk data directories, guessing it would have failed on that anyway even if it had found & ran the file.
OK, looking more closely at the output during the running of PyInstaller, I see that there are a few lines that look like they may be leading to my problem:
3541 INFO: Loading module hook 'hook-_tkinter.py'
ImportError: cannot import name 'Tcl'
3659 ERROR: Tcl/Tk improperly installed on this system.
I looked at the "hook-_tkinter.py" hook file (and read through the PyInstaller docs) but didn't see anything obviously amiss. But I'm not fully aware of all the details of the hook files and exactly what they need to contain (can anyone help with this???). Not exactly sure what the problem is but it appears PyInstaller is having an issue with linking into tkinter and that is causing my app(s) not to run. HAS ANYONE GOTTEN PyInstaller 3.2.1 TO EXECUTE EVEN A SIMPLE PYTHON 3.5 WINDOWS APP? IF SO, PLEASE SHARE HOW! I've done a ton of searching and reading but have not been able to uncover what the problem is yet. If anyone has a clue, please help. Any guidance is greatly appreciated!
A bit of additional info. Not sure why PyInstaller is saying Tcl/Tk is not properly installed. I just installed Python 3.5.3 and tkinter was installed automatically. Executed 'tkinter._text()' in a shell and it appears to work fine. All my uses of tkinter also appear to work fine under all versions of 3.5 under normal use of python. Only tkinter problem I'm having is with PyInstaller. Verified the exact version of Tcl/Tk installed with 'tkinter.Tcl().eval('info patchlevel')' and it reported '8.6.4'. Does anyone know of any other installation issues with Tcl/Tk that may be a problem? I did not do anything special to install tkinter, I just did a normal install of pyinstaller via 'pip install pyinstaller' after doing a fresh install of 'python 3.5.3'. Was there anything else I should have done? Any help is greatly appreciated!!!
Upvotes: 8
Views: 24289
Reputation: 145
I was having a similar issue with tkinter
and Python 3.5.
After looking over Understanding pyinstaller hooks I added the argument --hidden-import tkinter
.
pyinstaller --onefile --hidden-import tkinter hello.py
Upvotes: 13
Reputation: 1
I faced the same issue and was stuck for 6 hours hunting for the right answer. Now its working for me after I did the following steps:
After pyinstaller is installed, navigate to the folder where your program is (i.e in tkinter GUI)
In cmd, type:
pyinstaller program.py
That will fix your problems.
The solution I was found was uninstalling all the Python Interpreters and installing 2.7 version.
P.S. New to stackoverflow
Upvotes: -1