0

How to read with exe file files in exe file destination everytime newly when exe is executed?

If I add file with pyinstaller (--add-data) -> it's called bundled file. Then When I execute the exe file,...and I have already modified let's say edited some rows in current already EXE(bundled) folder I run exe file, then python does not see the newly modified file? It only reads the bundled one, which is like packages installed already in exe file.

This is not opinion based question; Maybe yes it is but I am trying to find an aswer to my question

I asked question yesterday, now reading pyinstaller Run time Information thoroughly,

When your app is running, it may need to access data files in one of the following locations:

Files that were bundled with it (see Adding Data Files).

Files the user has placed with the app bundle, say in the same folder.

Files in the user’s current working directory.

I am getting to think that the way I coded below, exe file only reads the file once when it was let's say pyinstalled(bundled), so before running exe file in dist folder when I edite excel file it does not read it. Is it right?

def resolve_path(path):
    if getattr(sys, "frozen", False):
        # If the 'frozen' flag is set, we are in bundled-app mode!
        resolved_path = os.path.abspath(os.path.join(sys._MEIPASS, path))
        print(resolved_path,'-+-')
    else:
        # Normal development mode. Use os.getcwd() or __file__ as appropriate in your case...
        resolved_path = os.path.abspath(os.path.join(os.getcwd(), path))
        print(resolved_path, '+-+')

    return resolved_path


with pd.ExcelWriter(resolve_path('outputFile/outputData.xlsm'), engine='openpyxl', mode='a', if_sheet_exists='overlay') as writer:
    book = load_workbook(resolve_path('outputFile/outputData.xlsm'), keep_vba=True)
xlmaster
  • 659
  • 7
  • 23
  • 1
    When you bundle files with your executable all of those files are frozen with the executable itself. any changes made to them while the program is running will not be saved and will be gone the next time you execute the app. You either need to use the one directory option instead of --onefile or simply don't bundle the file with the app. – Alexander Oct 24 '22 at 23:56
  • Even if I'll use `from os import path bundle_dir = path.abspath(path.dirname(__file__)) path_to_dat = path.join(bundle_dir, 'other-file.dat')`? I f I will not bundle the file , then how can I use them? – xlmaster Oct 25 '22 at 01:45
  • 1
    You would either need to pass the filepaths in as command line arguments or you would have to have them in a predefined path like the current working directory. – Alexander Oct 25 '22 at 02:08

0 Answers0