【问题标题】:pyinstaller not working with lxmlpyinstaller 不适用于 lxml
【发布时间】:2016-08-07 22:34:25
【问题描述】:

我正在尝试使用 pyinstaller 创建一个 exe,但一直遇到此错误

Traceback (most recent call last):
File "runautojama.py", line 28, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "autogen\jama_lib.py", line 24, in <module>
from lxml import html as htmlLib
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\lxml\html\__init__.py", line 54, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 546, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: DLL load failed: A dynamic link library (DLL) initialization     routine failed.
Failed to execute script runautojama

这些是由于导入语句

from lxml import etree
from lxml import html

我正在使用 lxml==3.6.0

我像这样为 lxml.etree 创建了钩子

import os.path
import glob

from PyInstaller.compat import EXTENSION_SUFFIXES
from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute

hiddenimports = collect_submodules('lxml')

binaries = []
lxml_dir = os.path.dirname(get_module_file_attribute('lxml'))
for ext in EXTENSION_SUFFIXES:
    lxmlMods = glob.glob(os.path.join(lxml_dir, '*%s*' % ext))
    for f in lxmlMods:
        binaries.append((f, 'lxml'))

还有一个简单的 lxml.html 钩子

from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute

hiddenimports = collect_submodules('lxml.html')

它将 etree.pyd 和其他 pyd 复制到路径中,但它似乎仍然不起作用,我仍然遇到同样的错误。你能建议我可能做错了什么吗?

我的规格文件:

a = Analysis(['..\\runautojama.py'],
             pathex=['scripts\\pyinstallerfiles'],
             binaries=None,
             datas=None,
             hiddenimports=['collections', 'urlparse', 'lxml._elementpath', 'functools', '__future__', 'gzip', 'lxml.html', 'lxml.includes'],
             hookspath=['scripts\pyinstallerfiles\hooks'],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

【问题讨论】:

标签: python lxml pyinstaller


【解决方案1】:

@WombatPM 感谢您指出这一点。使用开发版3.3.dev0+gd3e0cb4

解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 2022-06-20
    • 2021-09-20
    相关资源
    最近更新 更多