0

I have an interface I've created called interface.py that runs a script based on the press of a button...

def submit_action(selected_item): values = list(item_to_value[selected_item]) selected_month = month_var.get() # Check the state of the checkboxes and assign values invoice_value = "1" if invoice_var.get() else "0" loader_value = "1" if loader_var.get() else "0" # Append the checkbox values to the values list values.append(invoice_value) values.append(loader_value) values.append(selected_month) # Append the selected month if selected_item in ["Type 1", "Item 2", "Item 3"]: subprocess.run(["py", "gen_simple_management_fee.py"] + values) elif selected_item in ["Type 2", "Item 2", "Item 3"]: subprocess.run(["py", "gen_no_split_variant_2.py"] + values) elif selected_item in ["Type 3", "Item 5"]: subprocess.run(["py", "gen_fixed_split.py"] + values) elif selected_item in ["Type 4", "Item 5"]: subprocess.run(["py", "gen_daily_validations.py"] + values) elif selected_item in ["Type 5", "Type 6"]: subprocess.run(["py", "gen_variable_split.py"] + values) elif selected_item in ["Type 7", "Type 8"]: subprocess.run(["py", "gen_variable_split_variant_2.py"] + values) elif selected_item in ["Type 9", "Type 10"]: subprocess.run(["py", "gen_no_split.py"] + values) 

I also send a set of values across to the other scripts using a list that gets sent along with the subprocess call:

item_to_value = { "Type 1": ("Information 1", "information 2", "placeholder", "placeholder", "placeholder", "placeholder"), "Type 2": ("Information 1", "Information 2", "placeholder", "placeholder", "placeholder", "placeholder"), ... 

The script gets run, drawing on the subprocess information passed:

import pandas as pd import sys import os import tkinter as tk from tkinter import filedialog, Tk import customtkinter as ctk from PIL import Image corresponding_value = sys.argv[1] print(f"Running with corresponding value: {corresponding_value}") billing_project_name = sys.argv[6] selected_month = sys.argv[-1] selected_month = str(selected_month) ... 

When I try to package this as an .exe through pyinstaller, I either get the issue that the main interface.py file re-runs and displays another iteration of the gui, or the exe can't find the various scripts to run.

How can I make this work as an executable file? I want to avoid having to re-jig the code to run as multiprocessing instead of subprocess - unless it's the only way...

If there's a way to create an entrypoint script that runs the interface.py, then passes the correct variables and script to run, how would I do that? Any other ideas would be appreciated.

7
  • Did you include those scripts into the generated executable? Also it is better to use the embedded Python executable instead of py. Commented Aug 2, 2024 at 1:05
  • The files are present in the .spec file when I generate the .exe. I think the issue is related to how subprocess calls work - it reruns the initial script instead of locating and running the appropriate script. Maybe I'm referencing the files improperly? Commented Aug 2, 2024 at 1:35
  • 1
    You may need to get the actual paths of those scripts instead of using relative paths, see PyInstaller Run-time Information. Commented Aug 2, 2024 at 2:00
  • If the paths are all in the same directory at the time of creating the .exe, can you give me an example of how I would define the paths directly? I appreciate the responses Commented Aug 2, 2024 at 2:03
  • The link I posted in my past comment has example. Commented Aug 2, 2024 at 2:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.