Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with Pyinstaller with tkinter app on python 3.5

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!!!

like image 352
Sealyons Avatar asked Jun 13 '17 18:06

Sealyons


People also ask

Does Tkinter work with Python 3 3 5?

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.

Why doesn't pyinstaller work on macOS?

Turns out it is related to the path of Tcl/Tk on macOS. I found a workaround which involved compiling my own version of Pyinstaller, fixing the error, but breaking Pyinstaller for everything except macOS. I had the same problem but with Python 2.7.

What should I avoid when answering a Python Tkinter question?

But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our tips on writing great answers. Not the answer you're looking for? Browse other questions tagged python tkinter pyinstaller or ask your own question.


1 Answers

I was having a similar issues with tkinter and python 3.5 after looking over https://pythonhosted.org/PyInstaller/hooks.html#understanding-pyinstaller-hooks

add the option of --hidden-import tkinter

pyinstaller --onefile --hidden-import tkinter hello.py

like image 98
Tim Truty Avatar answered Sep 18 '22 15:09

Tim Truty