py2exe ctypes dll从编译的exe运行时加载错误,但在使用解释器运行代码时没有加载错误

时间:2014-10-28 17:59:04

标签: python ctypes py2exe

我正在使用py2exe编译和exe

当我测试从cmd运行的代码时,就像这样

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

它工作正常。

但是当我在执行生成的安装后运行它时,我得到:

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

我的猜测是setup.py中缺少一些配置,或者缺少ctypes lib的路径,但我在文档中找不到任何准确的信息。

非常感谢任何帮助或提示。 谢谢。 马里亚诺

编辑:这是_ctypes.py。我试图打印名称和路径变量。但是当从cmd运行exe时,它显示没有输出。

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

1 个答案:

答案 0 :(得分:0)

感谢评论家伙。我解决了它将ctypes和_ctypes packagaes添加到setup.py中的包含,如下所示:

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" ]
    }
}