Python Forum
PyInstaller OneFile - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PyInstaller OneFile (/thread-21646.html)



PyInstaller OneFile - felixS_zema - Oct-08-2019

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


RE: PyInstaller OneFile - Axel_Erfurt - Oct-08-2019

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 ...



RE: PyInstaller OneFile - snippsat - Oct-08-2019

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', '.')],



RE: PyInstaller OneFile - felixS_zema - Oct-09-2019

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.


RE: PyInstaller OneFile - felixS_zema - Oct-09-2019

Finally got it to work, thank you!