简体   繁体   中英

py2exe ctypes dll load error when running from compiled exe but not when running code using the interpreter

I'm compiling and exe using py2exe

when I test the code running from cmd like this

C:\wdir\mvl-tryton-client\tryton-3.2.3\bin>python tryton

it works fine.

But when I run it after executing the generated installation I get:

Error DLL load failed: The specified procedure could not be found.

File "tryton\common\common.pyc", line 1341, in process
File "tryton\gui\main.pyc", line 878, in _set_preferences
File "tryton\gui\main.pyc", line 1049, in sig_win_menu
File "tryton\gui\window\view_form\screen\screen.pyc", line 95, in __init__
File "tryton\gui\window\view_form\screen\screen.pyc", line 364, in switch_view
File "tryton\gui\window\view_form\screen\screen.pyc", line 384, in load_view_to_load
File "tryton\gui\window\view_form\screen\screen.pyc", line 397, in add_view_id
File "tryton\gui\window\view_form\screen\screen.pyc", line 425, in add_view
File "tryton\gui\window\view_form\view\widget_parse.pyc", line 4, in <module>
File "tryton\gui\window\view_form\view\form_gtk\__init__.pyc", line 3, in <module>
File "tryton\gui\window\view_form\view\form_gtk\parser.pyc", line 537, in <module>
File "tryton\gui\window\view_form\view\form_gtk\fingerprint.pyc", line 11, in <module>
File "tryton\gui\window\view_form\view\form_gtk\fpenroll.pyc", line 9, in <module>
File "ctypes\__init__.pyc", line 10, in <module>
File "_ctypes.pyc", line 12, in <module>
File "_ctypes.pyc", line 10, in __load

my guess is some missing configuration in the setup.py, or a missing path to the ctypes lib, but I couldn't find any precise info in the docs.

Any help or hint is greatly appreciated. Thanks. Mariano

EDIT: here is the _ctypes.py. I tried to print the name and path variables. But when running the exe from the cmd it shows no output there.

def __load():
    import imp, os, sys
    try:
        dirname = os.path.dirname(__loader__.archive)
    except NameError:
        dirname = sys.prefix
    path = os.path.join(dirname, '_ctypes.pyd')
    #print "py2exe extension module", __name__, "->", path
    mod = imp.load_dynamic(__name__, path)
##    mod.frozen = 1
__load()
del __load

Thanks for the comments guys. I solved it adding the ctypes and _ctypes packagaes to the includes in setup.py like this:

args['options'] = {
    'py2exe': {
        'optimize': 0,
        'bundle_files': 3,  # don't bundle because gtk doesn't support it
        'packages': [
            'encodings',
            'gtk',
            'pytz',
            'atk',
            'pango',
            'pangocairo',
            'gio',
            'ctypes',
            '_ctypes'
        ],
        'dll_excludes': [ "mswsock.dll", "powrprof.dll" ]
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM