Kiernan
Kiernan

Reputation: 31

How to fix Pyinstaller making an executable that doesn't run

I'm running python 3.7.0 32 bit version. I'm having issues turning a script into an executable. Pyinstaller successfully creates the build and dist folders and I have an executable but it doesn't do anything when I run it.

I've read other issues and I've used set Path=%Path%;C:\Windows\System32\downlevel; and i don't receive any warning about my dll files so they're all good. I have also tried on python 3.6.2 and experienced the same issues, I'm not sure whats going on.

This is the Hello World program I tried to do:

import tkinter as tk
class Go:
    def __init__(self,root):
        self.master = root
        self.frame = tk.Frame(self.master)
        self.testLabel = tk.Label(self.frame,text='hello world')
        self.testLabel.grid(row=0,column=0)
        self.frame.pack()

def main():
    root = tk.Tk()
    root.geometry('600x600')
    app = Go(root)

if __name__ == '__main__':
    main()

Run of pyinstaller:

C:\Users\kiern\AppData\Local\Programs\Python\Python37-32\Scripts>set Path=%Path%;C:\Windows\System32\downlevel;

C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts>pyinstaller --onefile test.py
73 INFO: PyInstaller: 3.4
75 INFO: Python: 3.7.0
76 INFO: Platform: Windows-10-10.0.17763-SP0
77 INFO: wrote C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\test.spec
83 INFO: UPX is not available.
87 INFO: Extending PYTHONPATH with paths
['C:\\Users\\kiern\\AppData\\Local\\Programs\\Python\\Python37- 
32\\Scripts',
'C:\\Users\\kiern\\AppData\\Local\\Programs\\Python\\Python37- 
32\\Scripts']
87 INFO: checking Analysis
91 INFO: Building Analysis because Analysis-00.toc is non existent
91 INFO: Initializing module dependency graph...
96 INFO: Initializing module graph hooks...
100 INFO: Analyzing base_library.zip ...
4348 INFO: running Analysis Analysis-00.toc
4381 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\kiern\appdata\local\programs\python\python37-32\python.exe
4792 INFO: Caching module hooks...
4798 INFO: Analyzing 
C:\Users\kiern\AppData\Local\Programs\Python\Python37-32\Scripts\test.py
4978 INFO: Loading module hooks...
4979 INFO: Loading module hook "hook-encodings.py"...
5081 INFO: Loading module hook "hook-pydoc.py"...
5084 INFO: Loading module hook "hook-xml.py"...
5360 INFO: Loading module hook "hook-_tkinter.py"...
5624 INFO: checking Tree
5627 INFO: Building Tree because Tree-00.toc is non existent
5629 INFO: Building Tree Tree-00.toc
5751 INFO: checking Tree
5754 INFO: Building Tree because Tree-01.toc is non existent
5755 INFO: Building Tree Tree-01.toc
5798 INFO: Looking for ctypes DLLs
5798 INFO: Analyzing run-time hooks ...
5803 INFO: Including run-time hook 'pyi_rth__tkinter.py'
5814 INFO: Looking for dynamic libraries
6094 INFO: Looking for eggs
6095 INFO: Using Python library 
c:\users\kiern\appdata\local\programs\python\python37-32\python37.dll
6096 INFO: Found binding redirects:
[]
6163 INFO: Warnings written to 
C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\build\test\warn-test.txt
6264 INFO: Graph cross-reference written to 
C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\build\test\xref-test.html
6323 INFO: checking PYZ
6323 INFO: Building PYZ because PYZ-00.toc is non existent
6324 INFO: Building PYZ (ZlibArchive) 
C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\build\test\PYZ-00.pyz
6937 INFO: Building PYZ (ZlibArchive) 
C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\build\test\PYZ-00.pyz completed successfully.
6947 INFO: checking PKG
6947 INFO: Building PKG because PKG-00.toc is non existent
6951 INFO: Building PKG (CArchive) PKG-00.pkg
9744 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
9812 INFO: Bootloader 
c:\users\kiern\appdata\local\programs\python\python37-32\lib\site- 
packages\PyInstaller\bootloader\Windows-32bit\run.exe
9812 INFO: checking EXE
9817 INFO: Building EXE because EXE-00.toc is non existent
9820 INFO: Building EXE from EXE-00.toc
9822 INFO: Appending archive to EXE 
C:\Users\kiern\AppData\Local\Programs\Python\Python37- 
32\Scripts\dist\test.exe
9832 INFO: Building EXE from EXE-00.toc completed successfully.

C:\Users\kiern\AppData\Local\Programs\Python\Python37-32\Scripts>

My expected goal is to have an executable that actually shows something. Any help please?

Edit: I just tried to do a simple program that does the main then prints hello world and the same issue occurred, the executable brings the cmd up for like 1 second then crashes or just stops and nothing happens

Upvotes: 0

Views: 1399

Answers (1)

Masoud Rahimi
Masoud Rahimi

Reputation: 6051

Your code is fine and runs without any errors but there is no output to see because you are forgetting to add mainloop() function to show your TK window.

import tkinter as tk


class Go:
    def __init__(self, root):
        self.master = root
        self.frame = tk.Frame(self.master)
        self.testLabel = tk.Label(self.frame, text='hello world')
        self.testLabel.grid(row=0, column=0)
        self.frame.pack()
        # dont forget this
        self.master.mainloop()


def main():
    root = tk.Tk()
    root.geometry('600x600')
    Go(root)


if __name__ == '__main__':
    main()

Then you can simply freeze your app with pyinstaller -F script.py.

Upvotes: 1

Related Questions