Open dcnieho opened 3 days ago
i do not want to include data_files of my app, but data files that come with a package used by my app
You say 'i do not want', but apparently you need zip_includes; It is similar to include_files
but copies the data files to the zip file.
ah ok! So, since these are not python files, I should manually make sure that the data files are found and included in the zip. Thanks for the pointer to the right functionality. Looking at for instance the hooks for OpenCV, i see that is what you do as well: https://github.com/marcelotduarte/cx_Freeze/blob/0dd2a31b42937c30739cab94bdb7451556fe4763/cx_Freeze/hooks/cv2.py
Is this always what you have to do if you're dealing with packaged with data files that are not handled by a hook? I am asking that also because i see another package, imgui_bundle, for which cx_Freeze has no specific support, but which does get all its data files included. I list that package in "zip_exclude_packages"
however, are those handled differently?
In fact, I force OpenCV to be kept outside of zip, because it doesn't work well in zip. And when I use this option (see line 59), data files are not copied, in the same way that they are not copied when using zip. Directories that do not have __init__
are generally not copied. If they have __init__
, they are considered a package and are treated differently by Python, which is then inherited by cx_Freeze.
In other words, we need to create hooks when we need to optimize a very large package (for example, PyTorch) or when it does not follow some Python rules (PyQt*). If it fails at some point, I create the hook. In general, packages that have a C interface need a hook.
An example where I needed to use zip-includes in a hook is tzdata when zip_include_packages is used, the data is not copied, so I copy it in this case.
Ok, thanks!
I've added the following to solve my problem:
def get_zip_include_files():
files = []
for d in site.getsitepackages():
base = pathlib.Path(d)
p = base / 'glassesValidator' / 'config'
for f in p.rglob('*'):
if f.is_file() and f.suffix not in ['.py','.pyc']:
files.append((f, pathlib.Path(os.path.relpath(f,base))))
return files
So in conclusion, it doesn't matter whether we're talking about data files of my project, or of packages, custom handling may be needed for them to be picked up.
We can make a hook for glassesValidator, which is simpler and can be reused by all users. I'll do it later.
I am not sure that is a good idea, I am almost certainly the only one that will be freezing an application using this package, its rather niche :)
Describe the bug I am not sure this is a bug, but i cannot find how to solve this in the manual/FAQ or with googling. This is different from the usual data_files question. In this case i do not want to include data_files of my app, but data files that come with a package used by my app (so data files contained in site_packages). How do i do that?
To Reproduce In a clean
venv
, runpip install glassesValidator
Test script to freeze (
test.py
):script to build the exe:
(that is a little more complicated than you'd hope, not all these packages work well from the zip, or are picked up correctly, but thats not the problem here).
When i run
test.py
from the venv, it works as expected, printing['markerPositions.csv', 'poster', 'targetPositions.csv', 'validationSetup.txt']
. When i run the frozen exe, i get:When i inspect
library.zip
, indeed themarkerPositions.csv
(and other non-python files) are missing fromglassesValidator/config
, while they are present in thesite_packages
of the environment used for building. If relevant, note that these data files are included in the package's manifest.Expected behavior Data files of a package used by the script that is being frozen are included in the library.zip.
Desktop (please complete the following information):