2022-10-24

Pyinstaller exe file pandas framework appends data to excel file in Temp folder but not in actual exe folder

What does pyinstaller EXE file do to excel file? pyinstaller -F --add-data "./outputFile/outputData.xlsm;./outputFile" main.py --onefile --clean --add-binary "./driver/chromedriver.exe;./driver" it takes file, puts in temp MEIPASS folder, appends new data to exel file which is there, but does not bring the appended excel file to the folder where exe file is. Why? I used both of the functions

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
    return os.path.join(base_path, relative_path)

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

none brought the file which is appended newly data, to the folder where all compiled files,scripts are.

I created exe file as written in this page ;

  • added function to find chromedriver
  • put the chromedriver to folder driver
  • created similar path to output file -put output file in folder

Does not write to output file.

I even added function from SO, write code in cmd from SO. I go to path of TEMP file there is folder name right, file name right. Even appends newly scraped data

    def resource_path(relative_path):
        """ Get absolute path to resource, works for dev and for PyInstaller """
        base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
        return os.path.join(base_path, relative_path)

    with pd.ExcelWriter(resource_path('./outputFile/outputData.xlsm'), engine='openpyxl', mode='a', if_sheet_exists='overlay') as writer:
        book = load_workbook(resource_path('./outputFile/outputData.xlsm'), keep_vba=True)

EDIT: It changes in temporary directory but do not bring in actual folder I ran from cmd pyinstaller with pyinstaller -F --add-data "./outputFile/outputData.xlsm;./outputFile" main.py --onefile --clean --add-binary "./driver/chromedriver.exe;./driver"



No comments:

Post a Comment