【发布时间】: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)
【问题讨论】:
-
你看过stackoverflow.com/questions/15114695/…和pythonhosted.org/PyInstaller/…吗?还有你使用的是什么操作系统,你能发布你的整个构建脚本吗?
-
是的,我确实经历过这个问题,我认为它不完全相同。我使用的是 Windows 7。我使用规范文件 sn-p 更新了我的问题
-
这似乎与发布到 github github.com/pyinstaller/pyinstaller/issues/2059的问题相同
标签: python lxml pyinstaller