Bwoodsend,
thank you for your reply.
I must confess that I’m a newbie/dummy in programming so if my project 
resembles you a C++ project is just by chance. Knowing the math behind the 
program, I asked ChatGPT to translate it into python code.
My goal is to distribute the final exe to colleagues who neither know 
python nor have python itself installed in their computer. Having different 
folder names serves the purpose of being as clear as possible with my 
colleagues.

The structure of the project is:
MyProjetcFolder
      |-----IO_Analysis.py
      |-----SIOT_2019.xlsx (input file)
      |-----Manual
      |             |---Manual.pdf
      |-----Results
      |             |---IO_ResultsBase.xlsx
      |             |---IO_ResultsDomImp.xlsx
      |             |---…
      |             |---…
      |-----src     
      |             |---Mod_Base.py
      |             |---Mod_DomImp.py
      |             |---…
      |             |---…
      |-----Temp_results
      |             |---key_value.txt
      |-----myvenv (virtual environment)

The original idea was to put the main script (IO_Analysis.py) in the src 
folder but I couldn’t manage to use input from and write results into same 
level (parallel?) folder, while if the main file is in the main folder 
everything seems to be easier.

The code in the main file is the following:
import tkinter as tk
import subprocess
import os

def run_python_file(file_path, root):
    # Run the specified Python file
    subprocess.Popen(['python', file_path], shell=True)
    # Close the current window
    root.destroy()

def open_excel_file():
    # Specify the path to the Excel file you want to open
    excel_file_path = "SIOT_2019.xlsx"

    # Check if the Excel file exists
    if os.path.isfile(excel_file_path):
        # Open the Excel file using the default program associated with 
.xlsx files
        subprocess.Popen([excel_file_path], shell=True)
        continue_program()
    else:
        # Display an error message if the Excel file does not exist
        error_message = "The specified Excel file does not exist."
        tk.messagebox.showerror("Error", error_message)

def continue_program():
    # Create a new Tkinter window for the second pop-up
    root2 = tk.Toplevel(root)
    root2.title("Select Python File")

    # Create a label with the question inside the first pop-up
    question_label = tk.Label(root2, text="Choose a model to run")
    question_label.pack()

    # Function to handle button clicks for Python files
    def button_click(file_path):
        run_python_file(file_path, root2)

    # Create six buttons for different Python files
    button1 = tk.Button(root2, text="Base Model", command=lambda: 
button_click("src\\\\\\\\Mod_Base.py"))
    button1.pack()

    button2 = tk.Button(root2, text="Domestic/Import Model", 
command=lambda: button_click("src\\\\\\\\Mod_DomImp.py"))
    button2.pack()

    button3 = tk.Button(root2, text="Employment Model", command=lambda: 
button_click("src\\\\\\\\Mod_Empl.py"))
    button3.pack()

    button4 = tk.Button(root2, text="Value Added Model", command=lambda: 
button_click("src\\\\\\\\Mod_VA.py"))
    button4.pack()

    button5 = tk.Button(root2, text="Endogenous Household Model", 
command=lambda: button_click("src\\\\\\\\Mod_EndHH.py"))
    button5.pack()

    button6 = tk.Button(root2, text="Cost/Price Model", command=lambda: 
button_click('src\\\\\\\\Mod_CostPrice_D.py'))
    button6.pack()

    # Run the Tkinter event loop for the second pop-up window
    root2.mainloop()

# Create the Tkinter window for the main background
root = tk.Tk()
root.title("Main Window")
root.attributes('-fullscreen', True)  # Set to fullscreen mode
root.configure(bg='blue')

def exit_fullscreen(event=None):
    root.attributes('-fullscreen', False)
    root.geometry("800x600")  # Optional: set to a reasonable size after 
exiting fullscreen

# Bind the Escape key to exit fullscreen mode
root.bind("<Escape>", exit_fullscreen)

# Function to minimize the window
def minimize_window():
    root.iconify()

# Function to toggle fullscreen mode
def toggle_fullscreen():
    if root.attributes('-fullscreen'):
        root.attributes('-fullscreen', False)
        root.geometry("800x600")
    else:
        root.attributes('-fullscreen', True)

# Function to close the window
def close_window():
    root.destroy()

# Create a frame for the custom title bar
title_bar = tk.Frame(root, bg='blue', relief='raised', bd=2)
title_bar.pack(side='top', fill='x')

# Add close button
close_button = tk.Button(title_bar, text='x', command=close_window, 
bg='light grey', fg='black', relief='flat')
close_button.pack(side='right', padx=5)

# Add maximize button
max_button = tk.Button(title_bar, text='⬜', command=toggle_fullscreen, 
bg='light grey', fg='black', relief='flat')
max_button.pack(side='right', padx=5)

# Add minimize button
min_button = tk.Button(title_bar, text='-', command=minimize_window, 
bg='light grey', fg='black', relief='flat')
min_button.pack(side='right', padx=5)

# Create a label for Input/Output Analysis title
title_label = tk.Label(root, text="Input/Output Analysis", bg='blue', 
fg='white', font=("Helvetica", 40))
title_label.pack(pady=(200, 10))  # Aumenta il valore del pady per spostare 
la label più in basso

# Create a frame for the central content
content_frame = tk.Frame(root, bg='blue')
content_frame.pack(expand=True)

# Create a label with the question inside the first pop-up
question_label = tk.Label(content_frame, text="Do you want to open the 
Excel Input file?", bg='blue', fg='white', font=("Helvetica", 16))
question_label.pack(pady=20)

# Create a frame for the buttons to be centered
button_frame = tk.Frame(content_frame, bg='blue')
button_frame.pack()

# Create the "Yes" button to open the Excel file with larger size
yes_button = tk.Button(button_frame, text="Yes", command=open_excel_file, 
font=("Helvetica", 16), width=10, height=2)
yes_button.pack(side="left", padx=10)

# Create the "No" button to continue the program with larger size
no_button = tk.Button(button_frame, text="No", command=continue_program, 
font=("Helvetica", 16), width=10, height=2)
no_button.pack(side="left", padx=10)

# Create the "Exit" button to close the main window
exit_button = tk.Button(button_frame, text="Exit", command=close_window, 
font=("Helvetica", 16), width=10, height=2)
exit_button.pack(side="left", padx=10)

# Funzione per aprire il file di help
def open_help_file():
    # Specifica il percorso del file di help
    help_file_path = "Manual\\\\\\\\IO_Analysis_Manual.pdf"  

    # Controlla se il file di help esiste
    if os.path.isfile(help_file_path):
        # Apri il file di help usando il programma predefinito associato ai 
file PDF
        subprocess.Popen([help_file_path], shell=True)
    else:
        # Mostra un messaggio di errore se il file di help non esiste
            error_message = "Il file di help specificato non esiste."
            tk.messagebox.showerror("Errore", error_message)

    # Creare il pulsante "Go to manual"
manual_button = tk.Button(button_frame, text="Go to Manual", 
command=open_help_file, font=("Helvetica", 16), width=15, height=2)
manual_button.pack(side="right", padx=100)

    # Run the Tkinter event loop for the main window
root.mainloop()


My question: are you suggesting me to move all the .py files in the main 
folder and then change the 5th line of the code (comments excluded)
subprocess.Popen(['python', file_path], shell=True) 
with     
import IO_Analysis; IO_Analysis.file_path()

Thank you for any additional help you can give me.

M

Il giorno domenica 30 giugno 2024 alle 18:39:59 UTC+2 bwoodsend ha scritto:

If I’m reading this right, you’ve got raw .py scripts in the src folder and 
presumably you’re running them as subprocesses using something akin to 
subprocess.run(["python", 
"src/IO_Analysis.py"]) or possibly something involving exec()? So you’re 
giving code to PyInstaller as data files so it has no idea that it needs to 
scan them for dependencies and you’re invoking that code using a random 
Python interpreter instead of the one PyInstaller collected so even if 
PyInstaller did know to collect numpy, you wouldn’t be able to use it 
anyway.

I suggest that you stop trying to structure your code like a C++ project. 
Move everything out of src and into the top level of your project then use 
import 
IO_Analysis; IO_Analysis.do_something() instead of whatever you're using to 
invoke the other scripts. Or better yet, learn how to properly structure 
Python projects 
<https://packaging.python.org/en/latest/tutorials/packaging-projects/>.
​

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/ee0037ed-4bec-4e68-bb2e-1b5f6770707dn%40googlegroups.com.

Reply via email to