Reputation: 31
I'm currently working on a program that accepts a specific file as input, works on the data and provides two graphs through Matplotlib (the only module imported in the data parsing file).
For this I have made a small GUI for the user to choose the file to have a graph made of. (w/ tkinter and PIL imported).
I have to make an app out of this and I'm using PyInstaller to it. Unfortunately I haven't been able to make the final file work (or run properly).
I have already made several modifications either to the code itself, but also to the PyInstaller's .spec file.
I have added the function to fix the path for PyInstaller. I have modified the .spec file to add the path to an image, not to show the console. I have tried with these settings both on/off: UPX, One File. I have checked the log files for missing modules as everything seems to be ok.
Some of the code:
Imports on the GUI file:
import sys
import os
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from PIL import ImageTk, Image
import rectifierDataParser
Imports on the Data Parsing file:
import sys
import os
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
GUI File:
class Application(tk.Frame):
def __init__(self, master = None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.fileButton = tk.Button(self, text(...))
self.quitButton = tk.Button(self, text(...))
self.fileButton.pack(side = 'top')
self.quitButton.pack(side = 'bottom')
def load_file(self):
filename = askopenfilename(title = "Select file", filetypes = [("Files", ("*.001", (...)))]
rectifierDataParser.main(filename)
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
app = Application()
app.master.title('Graphing Data')
app.master.geometry('300x200')
img = ImageTk.PhotoImage(Image.open("logo.jpg"))
panel = tk.Label(app, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
app.mainloop()
As I'm currently not able to see the GUI on the screen, is there any problem with the code itself or any compatibility with PyInstaller (supposedly PyInstaller is fully functional w/Tkinter).
I hope one of you might help me have a breakthrough as I have been stuck on this for way to much time! Many thanks in advance!
Upvotes: 3
Views: 4983
Reputation: 1629
I was having exactly the same problem and I fixed it by editing the .spec file.
I had to set
console=True
You'll find this option in the bottom of your .spec file.
Something like this:
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='YOU/EXECUTABLE/NAME',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True)
If you do not find your .spec file you can generate one by running
pyi-makespec yourprogram.py
Upvotes: 0
Reputation: 21
There is a few issues with the tcl version that comes with python, discussed here. I've written an script that automatically changes the init.tcl file to the correct version.
N.B. you shouldn't use the --onefile
flag as the file directories aren't present, and the script won't work.
cd /path/of/your/app
git clone https://github.com/jacob-brown/TCLChanger.git
pyinstaller --windowed app.py
python TCLChanger/TCLChanger.py
You should now be able to open your app, from the terminal and via double clicking.
Upvotes: 2