NewLionwang / dpkt

Automatically exported from code.google.com/p/dpkt
Other
0 stars 0 forks source link

__load_xxxx functions cause problem in pyinstaller or py2exe #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I got a problem after I generate exe with pyinstaller. It shows that dpkt
use some hacking way to import module. After I view the source code of
dpkt. I found that:

# XXX - auto-load Ethernet dispatch table from ETH_TYPE_* definitions
def __load_types():
    import os
    d = dict.fromkeys([ x[:-3] for x in
os.listdir(os.path.dirname(__file__) or '.') if x.endswith('.py') ])
    g = globals()
    for k, v in g.iteritems():
        if k.startswith('ETH_TYPE_'):
            name = k[9:]
            modname = name.lower()
            if modname in d:
                mod = __import__(modname, g)
                Ethernet.set_type(v, getattr(mod, name))

This hacking code load modules dynamically, so once it is packaged as exe
or something else, that function visit a wrong path like this
"\\buildcards\\out1.pyz/*.*"

Could you fix the problem by not to use strange hacking way to load
modules? Or provide some way to customize that behavior.

Thanks.

Original issue reported on code.google.com by Borns...@gmail.com on 30 May 2009 at 10:17

GoogleCodeExporter commented 8 years ago
An alternative solution:

http://www.py2exe.org/index.cgi/ConfigImportProblems

Otherwise, we need to build static mappings for Ethernet types, IP protocols, 
etc. 
without circular imports.

Original comment by dugsong on 26 Mar 2010 at 2:44

GoogleCodeExporter commented 8 years ago

Original comment by dugsong on 26 Mar 2010 at 2:45