Note that there are some explanatory texts on larger screens.

plurals
  1. POPython and py2exe - Implicitely Importing Modules
    primarykey
    data
    text
    <p>I've used py2exe several times in the past to create *.exe files for my python programs. However, I'm getting an error this time. I think I know what the issue is, but I don't know how to resolve it.</p> <p>I have a handful of wx.Panels in a subfolder and it could be a variable amount, so I import them via a function that finds the *.py files in the folder and calls the function below to actually import each panel.</p> <p>In normal python, this works well. However, py2exe leaves these files out. I assume that because they are not explicitly imported, py2exe doesn't believe they are needed. Is there a solution to this? Some option in py2exe that I'm unaware of?</p> <p>Thanks!</p> <pre><code># module = Module to be imported (string) # folder = Folder containing the module (string) def import_module(module, folder=None): if folder is None: return __import__(module) return getattr(__import__('%s.%s' % (folder.replace(os.path.sep, '.'), module)), module) ...within some other function... modules = [import_module(os.path.basename(os.path.splitext(filename)[0]), 'Panels') for filename in glob.glob('Panels//*.py')] </code></pre> <p><strong>EDIT</strong></p> <p>I'm adding a sample setup.py script I've used. But I've used probably 20 different variations and several completely different scripts (what I could find on the internet). Note that one requirement is that it is completely self-contained in one executable file.</p> <pre><code>from distutils.core import setup import py2exe import wxversion wxversion.select("2.8.12.1") import wx import wx.lib.pubsub includes = [] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter'] packages = ['wx.lib.pubsub'] dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll'] import glob my_data_files = [('Panels', glob.glob('Panels/*.py'))] setup( options = {"py2exe": {"compressed": 2, "optimize": 2, "includes": includes, "excludes": excludes, "packages": packages, "dll_excludes": dll_excludes, "bundle_files": 2, "dist_dir": "dist", "xref": False, "skip_archive": False, "ascii": False, "custom_boot_script": '', } }, zipfile = None, #data_files = my_data_files, windows=['Main.py'] ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload