I am creatign an app which I orginally created in Python. I then ran the Pyinstaller command to turn it into a shell script. I then inputed this shell script into Platypus to turn it in to a .app file. I have tried making the app in Pyinstaller, but it has issues too. Below, I have my orginal Python code, the command I ran to create the Pyinstaller script, and a screenshot of the Platypus app setup. As a note: When I run the shell script without making it an app, I recive no errors, and it works as expected.
import tkinter as tk
from tkinter import ttk
import os
import json
import logging
import datetime
import sys
logging.basicConfig(level=logging.DEBUG, filename='app.log', filemode='w',
format='%(name)s - %(levelname)s - %(message)s')
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
else:
application_path = os.path.dirname(__file__)
PREFERENCES_FILE = os.path.join(application_path, "user_preferences.json")
def save_preferences(data):
try:
with open(PREFERENCES_FILE, 'w') as f:
json.dump(data, f)
logging.info("Preferences saved successfully.")
except Exception as e:
logging.error(f"Failed to save preferences: {e}")
def load_preferences():
try:
if os.path.exists(PREFERENCES_FILE):
with open(PREFERENCES_FILE, 'r') as f:
return json.load(f)
except Exception as e:
logging.error(f"Error reading preferences: {e}")
return None
def delete_preferences():
try:
if os.path.exists(PREFERENCES_FILE):
os.remove(PREFERENCES_FILE)
logging.info("Preferences deleted successfully.")
except Exception as e:
logging.error(f"Failed to delete preferences: {e}")
def show_schedule(day, preferences):
schedule = preferences['schedule']
day_schedule = schedule.get(day, [])
schedule_text = f"Schedule for {day}:n"
for time_range, subject_key in day_schedule:
subject = preferences['subjects'].get(subject_key, "Free")
schedule_text += f"{time_range} - {subject}n"
schedule_label.config(text=schedule_text)
def setup_preferences():
def save_and_close():
subjects = {
'MESH1': mesh1_var.get(),
'MESH2': mesh2_var.get(),
'MESH3': mesh3_var.get(),
'MESH4': mesh4_var.get(),
'WL': wl_var.get(),
'WELLNESS': 'Wellness',
'ELECTIVE1': elective1_entry.get(),
'ELECTIVE2': elective2_entry.get(),
'CLUB': club_entry.get(),
'GEOMETRY': 'Geometry' if geometry_var.get() else None,
'RECESS': 'Recess',
'LUNCH': 'Lunch',
'ACADEMIC_COACHING': 'Academic Coaching',
'ADVISORY': 'Advisory'
}
wellness_day = wellness_day_var.get()
preferences = {
'subjects': subjects,
'schedule': load_default_schedule(geometry_var.get(), wellness_day)
}
save_preferences(preferences)
setup_root.destroy()
main_app()
setup_root = tk.Tk()
setup_root.title("Setup Preferences")
mesh_options = ["Math", "English", "Science", "History"]
wl_options = ["Spanish", "French", "FOL"]
day_options = ['A', 'B', 'C', 'D', 'E', 'F'] # Days of the schedule
mesh1_var, mesh2_var, mesh3_var, mesh4_var, wl_var = tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar(), tk.StringVar()
geometry_var = tk.BooleanVar()
wellness_day_var = tk.StringVar(value='')
ttk.Label(setup_root, text="Select MESH 1:").pack()
ttk.Combobox(setup_root, textvariable=mesh1_var, values=mesh_options).pack()
ttk.Label(setup_root, text="Select MESH 2:").pack()
ttk.Combobox(setup_root, textvariable=mesh2_var, values=mesh_options).pack()
ttk.Label(setup_root, text="Select MESH 3:").pack()
ttk.Combobox(setup_root, textvariable=mesh3_var, values=mesh_options).pack()
ttk.Label(setup_root, text="Select MESH 4:").pack()
ttk.Combobox(setup_root, textvariable=mesh4_var, values=mesh_options).pack()
ttk.Label(setup_root, text="Select WL:").pack()
ttk.Combobox(setup_root, textvariable=wl_var, values=wl_options).pack()
ttk.Label(setup_root, text="Select Wellness Day:").pack()
ttk.Combobox(setup_root, textvariable=wellness_day_var, values=day_options).pack()
ttk.Checkbutton(setup_root, text="Include Geometry", variable=geometry_var).pack()
ttk.Label(setup_root, text="Enter AM ICE:").pack()
elective1_entry = ttk.Entry(setup_root)
elective1_entry.pack()
ttk.Label(setup_root, text="Enter PM ICE:").pack()
elective2_entry = ttk.Entry(setup_root)
elective2_entry.pack()
ttk.Label(setup_root, text="Enter Club:").pack()
club_entry = ttk.Entry(setup_root)
club_entry.pack()
ttk.Button(setup_root, text="Save and Start", command=save_and_close).pack(pady=10)
setup_root.mainloop()
def load_default_schedule(include_geometry, wellness_day):
today = datetime.datetime.today().weekday() # Monday is 0 and Sunday is 6
geometry_days = [0, 2, 4] # Monday, Wednesday, Friday
schedule = {
'A': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "CLUB"), ("9:20-10:10", "MESH1"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH3"), ("11:20-12:10", "MESH2"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "WL"), ("1:30-2:20", "MESH4"), ("2:20-3:10", "ELECTIVE2")],
'B': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "ELECTIVE1"), ("9:20-10:10", "WL"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH2"), ("11:20-12:10", "MESH3"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "MESH4"), ("1:30-2:20", "MESH1"), ("2:20-3:10", "ELECTIVE2")],
'C': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "ACADEMIC_COACHING"), ("9:20-10:10", "MESH2"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH4"), ("11:20-12:10", "MESH1"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "WL"), ("1:30-2:20", "MESH3"), ("2:20-3:10", "ELECTIVE2")],
'D': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "ELECTIVE1"), ("9:20-10:10", "WL"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH4"), ("11:20-12:10", "MESH1"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "MESH3"), ("1:30-2:20", "MESH2"), ("2:20-3:10", "ACADEMIC_COACHING")],
'E': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "ELECTIVE1"), ("9:20-10:10", "MESH1"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH3"), ("11:20-12:10", "MESH2"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "WELLNESS"), ("1:30-2:20", "MESH4"), ("2:20-3:10", "ELECTIVE2")],
'F': [("8:10-8:30", "ADVISORY"), ("8:30-9:20", "ELECTIVE1"), ("9:20-10:10", "WL"),
("10:10-10:30", "RECESS"), ("10:30-11:20", "MESH2"), ("11:20-12:10", "MESH3"),
("12:10-12:40", "LUNCH"), ("12:40-1:30", "MESH4"), ("1:30-2:20", "MESH1"), ("2:20-3:10", "ACADEMIC_COACHING")]
}
wellness_time_slot = "12:40-1:30"
for day, activities in schedule.items():
if day == wellness_day:
activities = [(time, subject) if subject != "WL" else (time, "WELLNESS") for time, subject in activities]
schedule[day] = activities
if include_geometry and today in geometry_days:
geometry_class = ("7:00-8:00", "GEOMETRY")
for key in schedule.keys():
schedule[key].insert(0, geometry_class)
return schedule
def main_app():
preferences = load_preferences()
if not preferences:
setup_preferences()
return
root = tk.Tk()
root.title("School Schedule")
day_var = tk.StringVar(value='A')
day_dropdown = ttk.Combobox(root, textvariable=day_var, values=list('ABCDEF'))
day_dropdown.pack(pady=10)
show_button = ttk.Button(root, text="Show Schedule", command=lambda: show_schedule(day_var.get(), preferences))
show_button.pack(pady=5)
reset_button = ttk.Button(root, text="Reset Preferences", command=lambda: [delete_preferences(), root.destroy(), setup_preferences()])
reset_button.pack(pady=5)
global schedule_label
schedule_label = tk.Label(root, text="", justify=tk.LEFT)
schedule_label.pack(pady=10)
root.mainloop()
if __name__ == "__main__":
main_app()
pyinstaller --windowed --onefile --icon=/Users/jacob/ icon.iconset/857457.icns --name="School Schedule" /Users/jacob/School_Schedule_App_v1.1.py
Platypus Screen of Setting Up Shell Script to Create the App
When I try to run the app, the console text box appears and gives me the error:
“/Users/jacob/Built/School Schedule 1.1.app/Contents/Resources/script: /Users/jacob/Built/School Schedule 1.1.app/Contents/Resources/script: cannot execute binary file”
Why is this, and how do I fix it? If there is any additonal information you need, please let me knwo and I will do my best to give you the most accurate details. Thank you.
JSB10 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.