0

I am trying to create an exe using pyinstaller but keep running into this error

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

These are due to the import statements

from lxml import etree
from lxml import html

I am using lxml==3.6.0

I created hooks for lxml.etree like this

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'))

And a simple hook for lxml.html

from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute

hiddenimports = collect_submodules('lxml.html')

It copies the etree.pyd and other pyd's to the path but it still doesnt seem to work and I still get the same error. Can you suggest what I might be doing wrong.

My spec file:

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)
Andrew Svetlov
  • 16,730
  • 8
  • 66
  • 69
kaosar
  • 141
  • 11
  • Have you looked at http://stackoverflow.com/questions/15114695/pyinstaller-import-error?rq=1 and http://pythonhosted.org/PyInstaller/when-things-go-wrong.html#helping-pyinstaller-find-modules ? Also what os are you using and can you post your entire build script. – WombatPM Aug 07 '16 at 23:56
  • Yeah I have indeed gone through that question, I think its not exactly the same. I am using Windows 7. I updated my question with the spec file snippet – kaosar Aug 08 '16 at 01:40
  • This appears to be the same issue as posted to github https://github.com/pyinstaller/pyinstaller/issues/2059 – WombatPM Aug 08 '16 at 07:03

1 Answers1

0

@WombatPM thanks for pointing it out. The problem gets resolved using the dev version 3.3.dev0+gd3e0cb4

kaosar
  • 141
  • 11