How to include resource file in cx_Freeze binary
Question: I am trying to convert a python package to a linux binary (and eventually a
windows executable as well) using cx_Freeze. The package has dependency upon
multiple egg files, as i understand cx_Freeze doesn't play nice with egg
files, so i unzipped the egg files. One of the egg files has a resource string
file 'test.resource' in some package 'test.package', to include this resource
string file i used -

    
    
    include_files = ['test/package/test.resource']
    

Now i see this file is being copied to the target directory along with the
binary but when i try to run the binary i get the error - "IOError: [Errno 2]
No such file or directory: 'test/package/test.resource'"

The code trying to read the file is doing this:

    
    
    from pkg_resources import resource_string
    strings = resource_string("test.package", "test.resource")
    

How can i add this resource file so that it's available to the generated
binary?


Answer: Since the accepted answer is light on details, I thought I'd provide a
solution that worked for me. It does not require that you unzip your egg
files, but does not preclude it either.

**The situation** : I have an application that we package with
[esky](https://pypi.python.org/pypi/esky) using the `cx_Freeze` freezer, but
this information should apply equally well to applications just using
`cx_Freeze` directly. The application makes use of the
[treq](https://github.com/twisted/treq) library which includes the following
line in `treq.__import__`:

    
    
    __version__ = resource_string(__name__, "_version").strip()
    

I use `pkg_resources` to determine the filepath of the `_version` file and
manually add it to my `zip_includes`. We make sure it gets placed into its
expected location alongside the rest of the `treq` library files. In my
`setup.py` file I have:

    
    
    setup(
        name=...,
        version=...,
        install_requires=[
            ...,
            treq==15.0.0,
            ...
        ],
        ...,
        options={
            ...,
            "bdist_esky": {
                ...,
                "freezer_options": {
                    # This would be "zip_includes" in options if just using cx_Freeze without esky
                    "zipIncludes": [
                        # Manually copy the treq _version resource file into our library.zip
                        (pkg_resources.resource_filename('treq', '_version'), 'treq/_version')
                    ],
                    "packages": [..., "treq", ...]
                    ...,
                ...,
            ...,
        ...,
    )
    

**Bonus** : While one does not have to unzip libraries in order for this to
work, it seems to be useful enough in general that you might want to always
unzip them upon installation (a la `python setup.py develop`). It's a simple
matter of adding the following lines to your application's `setup.cfg`:

    
    
    [easy_install]
    zip_ok = 0
    

Then, when you run `python setup.py develop`, your dependencies are installed
into `site-packages` in their expanded directory form.

