Python Forum
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
Reply
#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 ...
Reply
#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', '.')],
Reply
#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.
Reply
#5
Finally got it to work, thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyinstaller --onefile mhzr 6 3,197 Jun-24-2021, 05:56 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020