Python Forum
Problems with PyInstaller with tkinter app on python 3.5
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with PyInstaller with tkinter app on python 3.5
#1
Just getting started with Pyinstaller (and somewhat with Tk windowing) and having trouble getting my tkinter windows app (under python 3.5.3) 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 also tried the latest development version of PyInstaller (3.3) but it gave the same issues.

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 (but nothing really helpful at this point) ending in this error message:

Failed to execute script pyi_rth_tkinter.

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:

Error:
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!!!
Reply
#2
I am not sure why you are getting this error either.
One possibility, though it shouldn't create an error is that you import the entire tkinter library with
from tkinter import *
Even though it's a bit more work, it's better to import only the portions that you are actually using.
better to use:
# from tkinter import *
import tkinter as tk

root = tk.Tk()
root.title("Test Window")

# Setup window widgets and place on window
l1 = tk.Label(root, text='Hello World!', font=("Verdana", 18))
l2 = tk.Label(root, text='Hello World!', font=("Times New Roman", 9))
b1 = tk.Button(root, text='Button 1', font=("Verdana", 12), state=tk.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()
just out of curiosity, try that and see if you're OK
Reply
#3
Thanks for looking.  Made the change and tried but same results (as expected).  Yes, I do realize that importing the entire library is wasteful from a memory perspective. But in this case it really isn't in an issue for us since the distribution for the actual app is very limited, just to our specific customers and the file size is not an problem.

Have you (or anyone) been able to get PyInstaller (3.2.1) to run successfully with a tkinter windowing app on python 3.5 ????  I haven't been able to get much help from anyone on this issue anywhere I've posted this question so far.  

Has anyone had any better luck using cx_Freeze, py2exe, py2app, or any other python freezing applications for python windowing apps using tkinter ???

Appreciate any additional help from anyone!
Reply
#4
(Jun-15-2017, 05:47 PM)sealyons Wrote: Has anyone had any better luck using cx_Freeze, py2exe, py2app, or any other python freezing applications for python windowing apps using tkinter ???
I have used py2exe in the past, however with python2.7.
Reply
#5
(Jun-15-2017, 05:47 PM)sealyons Wrote: as anyone had any better luck using cx_Freeze, py2exe, py2app, or any other python freezing applications for python windowing apps using tkinter ???
I have used theme all.
Work fine for me with just pyinstaller tk_test.py tk_test.py is just copy of code in your post.
I have so much installed so i use virtual environment(a part of 3.5-->) a lot to avoid conflicts,and also good to use with Freeze tools.
Here a run with Python 3.5:
C:\Python35
λ python -m venv py_inst

C:\Python35
λ cd py_inst

C:\Python35\py_inst
λ C:\Python35\py_inst\Scripts\activate.bat

# Now environment is active 
(py_inst) C:\Python35\py_inst
λ pip install pyinstaller
Collecting pyinstaller
 Using cached PyInstaller-3.2.1.tar.bz2
Collecting future (from pyinstaller)
 Using cached future-0.16.0.tar.gz
Collecting pypiwin32 (from pyinstaller)
 Using cached pypiwin32-219-cp35-none-win32.whl
Installing collected packages: future, pypiwin32, pyinstaller
 Running setup.py install for future ... done
 Running setup.py install for pyinstaller ... done
Successfully installed future-0.16.0 pyinstaller-3.2.1 pypiwin32-219

# Run pyinstaller
(py_inst) C:\Python35\py_inst
λ pyinstaller tk_test.py
----- installing ------

# To test "exe" cd into dist
(py_inst) C:\Python35\py_inst
λ cd dist
(py_inst) C:\Python35\py_inst\dist
λ cd tk_test

# Run "exe"
(py_inst) C:\Python35\py_inst\dist\tk_test
λ tk_test.exe
Reply
#6
Well, not really sure what the problem with this is. I did a clean install (python 3.5.3 & pyInstaller) on another computer and everything works correctly. Going to try to uninstall all python instances (and pyInstaller) on the first computer and reinstall again and see if I can get it to properly run there.
Reply
#7
Have a python 3.5.3 windows app (using tkinter) frozen and deployed with PyInstaller 3.2.1 (32-bit) that is having trouble running on 32-bit Win7PRO SP1 systems.  Here are the error messages it is displaying when trying to run:

Error:
The procedure entry point ucrtbase.terminate could not be located in the dynamic link library api-ms-win-crt-runtime-l1-1-0.dll. error loading Python DLL: c:\users\Mapples--\AppData\Local\Temp\_MEI26442\python35.dll (error code 127)
The code appears to work fine on all 64-bit Win7PRO SP1 machines deployed to (with PyInstaller 3.2.1) and when running directly in python but the listed errors are displayed when running the frozen .exe on 32-bit windows.  Does anyone have any ideas about what may be causing this?  Appreciate any help.  Thanks.
Reply
#8
which version of python - 32 or 64 bit you use?
Reply
#9
Python 32-bit.
Reply
#10
python35.dll should never be loaded from a Temp folder.
All data in Temp folders can be deleted,c:\users\Mapples--\AppData\Local\Temp\
when you install Python a Temp folder is used,
it should of course not using files from Temp folder after install has been done.

For me it not important at all if it work on OS version Python,because of conflict and others stuff.
I do not do a new clean Python install because of this.
A virtual environment is like a clean install of Python,
it really solve most problem a OS install can have like conflict and Permission errors.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyinstaller 3 Python 2 mckymntl 0 1,234 Feb-07-2022, 06:28 AM
Last Post: mckymntl
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,702 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable kmarien 3 3,681 Nov-30-2020, 04:10 PM
Last Post: buran
  'No module named tkinter.messagebox' - PyInstaller ironfelix717 7 8,206 Jan-19-2020, 06:56 AM
Last Post: buran
  Cannot Change Python script to exe using Pyinstaller omar_mohsen 3 2,398 Dec-19-2019, 01:05 PM
Last Post: buran
  Problems running exe file from pyinstaller ersa21 4 7,867 Jan-15-2019, 06:36 PM
Last Post: snippsat
  Error with using pyinstaller to convert python script in Mac OS Takeshio 2 5,391 Oct-19-2018, 02:42 PM
Last Post: Takeshio
  compiling python using pyinstaller sabeesh90 0 2,670 Aug-16-2018, 09:58 AM
Last Post: sabeesh90
  [split] Trouble making my first python .exe using pyinstaller. esha09 5 7,205 Apr-21-2018, 09:37 PM
Last Post: snippsat
  Python to Exe trouble (TKinter might be causing problems?) Bill 5 11,614 Oct-02-2017, 10:02 PM
Last Post: Bill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020