I am trying to build a one-file EXE file with Pyinstaller that opens a tkinter GUI. For some reason though, the EXE does not open any tkinter windows when ran. I wrote a quick code to test if Pyinstaller was having issues with the tkinter module. It looks like this:
import tkinter
root= tkinter.Tk()
canvas1 = tkinter.Canvas(root, width = 300, height = 300)
canvas1.pack()
def hello ():
label1 = tkinter.Label(root, text= 'Hello World!', fg='green', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 200, window=label1)
button1 = tkinter.Button(text='Click Me',command=hello, bg='brown',fg='white')
canvas1.create_window(150, 150, window=button1)
root.mainloop()
When tkinter is the only module being imported, the EXE file built by Pyinstaller runs without issues. But when I add all of the other imports that my GUI program uses, the compiled one-file EXE no longer opens the tkinter window:
import tkinter
import tkinter.filedialog
import os
import PIL
import numpy as np
import math
import win32api
import ctypes
import peakutils
import matplotlib
import skimage.measure
import scipy
import astropy.modeling
import cv2
import sklearn.neighbors.NearestNeighbors
import imutils
import sys
...
I read the documentation of the imported modules, and there are some duplicate dependencies (astropy.modeling imports scipy, for example). Is this kind of double-dependency why Pyinstaller isn't able to build a working EXE, or is there another reason? I realize that there are a lot of imported modules, could this also be why the EXE won't work? How can I fix this? I should also add that Pyinstaller didn't return any errors when building either of the EXEs.