cx_Freeze is not finding self defined modules in my project when creating exe
Question: I have a project that runs from GUI.py and imports modules I created.
Specifically it imports modules from a "Library" package that exists in the
same directory as GUI.py. I want to freeze the scripts with cx_Freeze to
create a windows executable, and I can create the exe, but when I try to run
it, I get: "ImportError: No module named Library."

I see in the output that all the modules that I import from Library aren't
imported. Here's what my setup.py looks like:

    
    
    import sys, os
    from cx_Freeze import setup, Executable
    
    build_exe_options = {"packages":['Libary', 'Graphs', 'os'], 
                     "includes":["tkinter", "csv", "subprocess", "datetime", "shutil", "random", "Library", "Graphs"],
             "include_files": ['GUI','HTML','Users','Tests','E.icns', 'Graphs'],
            }
    
    base = None
    exe = None
    if sys.platform == "win32":
    exe = Executable(
        script="GUI.py",
        initScript = None,
        base = "Win32GUI",
        targetDir = r"built",
        targetName = "GUI.exe",
        compress = True,
        copyDependentFiles = True,
        appendScriptToExe = False,
        appendScriptToLibrary = False,
        icon = None
    )
    base = "Win32GUI"
    
    setup( name = "MrProj",
    version = "2.0",
    description = "My project",
    options = {"build.exe": build_exe_options},
    #executables = [Executable("GUI.py", base=base)]
    executables = [exe]
    )
    

I've tried everything that I could find in StackOverflow and made a lot of
fixes based upon similar problems people were having. However, no matter what
I do, I can't seem to get cx_freeze to import my modules in Library.

My setup.py is in the same directory as GUI.py and the Library directory.

I'm running it on a Windows 7 Laptop with cx_Freeze-4.3.3.

I have python 3.4 installed.

Any help would be a godsend, thank you very much!


Answer: If `Library` (funny name by the way) in `packages` doesn't work you could try
as a workaround to put it in the `includes` list. For this to work you maybe
have to explicitly include every single submodule like:

    
    
    includes = ['Library', 'Library.submodule1', 'Library.sub2', ...]
    

For the `include_files` you have to add each file with full (relative) path.
Directories don't work.

You could of course make use of `os.listdir()` or the `glob` module to append
paths to your include_files like this:

    
    
    from glob import glob
    ...
    include_files = ['GUI.py','HTML','Users','E.icns', 'Graphs'],
    include_files += glob('Tests/*/*')
    ...
    

In some cases something like `sys.path.insert(0, '.')` or even
`sys.path.insert(0, '..')` can help.

