0

I have a Python application in a directory dir. This directory has a __main__.py file and several data files that are read by the application using open(...,'r'). Without editing the code, it it possible to bundle the code and data files into a single zip file and execute it using something like python app.pyz

  • My goal is to share the file and data easily.
  • Running the application using python dir works fine.
  • If I make a zip file using python -m zipfile -c app.pyz dir/*, the resulting application will run but cannot read the files. This makes sense.
  • I can ask the customers to unzip the compressed folder before running or I could embed the files as strings within the code. That said, I'm curious of this can be avoided.

Can I bundle code and data into one file?

RyeGrain
  • 37
  • 5
  • Does this answer your question? [How can I make a Python script standalone executable to run without ANY dependency?](https://stackoverflow.com/questions/5458048/how-can-i-make-a-python-script-standalone-executable-to-run-without-any-dependen) – Kraigolas Jan 19 '22 at 02:22
  • You can have a **build** script, that will assemble a file containing the data you want into a python file, that can be imported with Python. But if the data is large, I would not recommend it. Instead, you could read the original files directly from inside the zipfile. – Lenormju Jan 19 '22 at 15:11
  • Thank you both. Both answers are more work than is reasonable in this case. Place this into an answer and I'll mark it as accepted. – RyeGrain Jan 21 '22 at 00:17

0 Answers0