The issue here is that this forum is about PyInstaller, and your problem is
more core Python than that.

What you need to do, as Bob suggested is make your code into a "proper"
python application / package:

https://packaging.python.org/en/latest/tutorials/packaging-projects/

The challenge is that those docs are oriented towards making a package that
one might publish -- which is not what you want to do, but the core
concepts are the same -- you want a package for your code, and one
top-level script to run the application.

As for help from human intelligence, you might try:

https://discuss.python.org/

But my suggestion is that you have the approach of:

"I want help learning how to make a Python application"

rather than

"How can I get this working ASAP without having to learn too much?"

The latter is what paid consultants are for.

Good luck.

-CHB


On Mon, Jul 1, 2024 at 12:17 PM Marco Fioramanti <marco.fiorama...@gmail.com>
wrote:

> I’m an economist not a programmer and I’m perfectly aware that my code is
> far from being optimized. I had some python courses online but they rarely
> go beyond the “Hello world” stuff. On the other hand, with hundreds of
> trial and error I was able to get a quite complex (for me) project which
> does exactly what it was supposed to do. What I can’t manage is to create a
> python free exe with pyinstaller. In addition I see that the
> “ModuleNotFoundError” is quite common…not only among economists.
>
> @bwoodsend If you have the authority to throw me out of the forum then do
> it, otherwise I suggest you to not waste your time just ignoring my
> questions.
>
> @Chris Barker the reason I joined the forum was indeed to look for help
> from human intelligence, not to stimulate the acrimony against the AI which
> is, at the end of the day, a product of programmers.
> Any additional hint will be appreciated.
>
> M
> Il giorno lunedì 1 luglio 2024 alle 19:36:41 UTC+2 Chris Barker ha scritto:
>
>> On Mon, Jul 1, 2024 at 7:12 AM Marco Fioramanti <marco.fi...@gmail.com>
>> wrote:
>>
>>>  Knowing the math behind the program, I asked ChatGPT to translate it
>>> into python code.
>>>
>>
>> Well, there's your problem :-(
>>
>> ChatGPT has written some horrible code for you.
>>
>> All the Popen calls are interesting, and well,  totally unnecessary .
>> What's interesting (to me) is that I've seen ChatGPT code like that, but in
>> that case, it was asked to translate a shell scripts into python,  so the
>> Popen stuff made sense, but in this case -- WTF?
>>
>> I guess we programmers are not out of job just yet :-)
>>
>> My advice is to try to make this the proper Python. With luck the TkInter
>> code and the math code are OK, and all you need to do is replace all the
>> Open calls with plain Python calling of functions, but ?????
>>
>> Not sure what to tell you other that you'll need to learn some Python --
>> and/or get a "naturally intelligent" person to help.
>>
>> -CHB
>>
>>
>>
>>
>>
>>
>>
>>> 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 pyinstaller...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pyinstaller/ee0037ed-4bec-4e68-bb2e-1b5f6770707dn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/pyinstaller/ee0037ed-4bec-4e68-bb2e-1b5f6770707dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>>
>> Christopher Barker, Ph.D.
>> Oceanographer
>>
>> Emergency Response Division
>> NOAA/NOS/OR&R            (206) 526-6959   voice
>> 7600 Sand Point Way NE   (206) 526-6329   fax
>> Seattle, WA  98115       (206) 526-6317   main reception
>>
>> chris....@noaa.gov
>>
> --
> 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 pyinstaller+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyinstaller/3a1484e4-1d7a-4423-933b-a127a7780cd2n%40googlegroups.com
> <https://groups.google.com/d/msgid/pyinstaller/3a1484e4-1d7a-4423-933b-a127a7780cd2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov

-- 
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 pyinstaller+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/CALGmxEJW0smXsB9k1mQNAQAVX2xuO8fq%2BWRTEy9L4daW%3DoQboQ%40mail.gmail.com.

Reply via email to