简体   繁体   English

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

[英]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 我正在编译并使用py2exe exe

when I test the code running from cmd like this 当我像这样测试从cmd运行的代码时

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. 我的猜测是setup.py中缺少某些配置,或者ctypes lib缺少路径,但是我在文档中找不到任何准确的信息。

Any help or hint is greatly appreciated. 任何帮助或提示,我们将不胜感激。 Thanks. 谢谢。 Mariano 马里亚诺

EDIT: here is the _ctypes.py. 编辑:这是_ctypes.py。 I tried to print the name and path variables. 我试图打印名称和路径变量。 But when running the exe from the cmd it shows no output there. 但是从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

Thanks for the comments guys. 感谢您的评论。 I solved it adding the ctypes and _ctypes packagaes to the includes in setup.py like this: 我解决了将ctypes和_ctypes packagaes添加到setup.py中的include中,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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