My python program needs to extract data from a zip which also is in the executable's directory. When adding the zip file to the pyinstaller when compiling my script. The exe is later unable to find the zip file as it seems not to be in the executables directory
I have seen this post https://stackoverflow.com/a/13790741 but can't understand how to apply what where. Simply pasting the code snippet into my own .py did not solve the issue.
My code that deals with the zip file:`
with zipfile.ZipFile("data.zip", 'r') as zip_ref:
zip_ref.extractall(pte2)
pyinstaller --noconfirm --onefile --windowed --add-data "C:/Users/User/Downloads/dir/data.zip;." "C:/Users/User/Downloads/dir/program.py"
The question: How can I tell pyinstaller to bundle the zip file and the .py into the same exe and have my .py still find the zip file?
So after some more trial and error I got it working. In your script, where you access a file, in my case data.zip. do it like this:
with zipfile.ZipFile(os.path.join(sys._MEIPASS, "data.zip"), 'r') as zip_ref:
zip_ref.extractall(pte2)
Then use
pyinstaller --noconfirm --onefile --windowed --add-data "C:/Users/User/Downloads/dir/data.zip;." "C:/Users/User/Downloads/dir/program.py"