Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 PyInstaller OneFile
#1
Hey,

I built an application and bundled it with PyInstaller. It includes some datas in the spec file, like images and excel sheets. Is there a way I can bundle my app as onefile except for e.g. the excel sheets, so that I can change them later? What I want to have is a single exe file and a folder with some excel files that are used in the app.

Thanks for any help,

Best regards,
Felix
Quote
#2
Create a folder ("Resources") in the same folder where the script is

and then change your script (for example)

import os
import sys
mydir = os.path.join(os.path.dirname(sys.argv[0]), "Resources")
excelfile = os.path.join(mydir, "myexcelfile.csv")
if os.path.isfile(excelfile ):
    print("exists") ### to check file exists
    # your code ...
Quote
#3
Build to one file and give no Path.
Then should the one .exe file find files that are in same dist folder.
I guess you most keep file name the same or have most have a way that read files in eg openpyxl.
from openpyxl import load_workbook

wb = load_workbook(filename='some.xlsx')
Build could eg be:
pyinstaller --onefile --console --add-data some.xlsx;.
In spec file it would be,there also easier to add more file if needed.
datas=[('some.xlsx', '.')],
Quote
#4
So if I try to load a file only by its name python looks into the directory where the exe-file is located? Then I would not have to add them in the spec-file, would I? Because I don't know what files are later put in. I want to make the files exchangeable but I don't want to have that huge directory tree if I don't do --onefile.
Quote
#5
Finally got it to work, thank you!
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)