Google Groups

newbie help : "dynamic import" from reportlab . How to solve ImportError without forcing import in code


harijay Jan 25, 2012 1:32 PM
Posted in group: PyInstaller
Hi

I can get PyInstaller to build a free standing installer for my
wxpython application with several binary dependencies ( reportlab ,
PyYaml , wx )

When I run the exe file I get an ImportError during running the app
which occurs due to the reportlab pdf generation library dynamically
importing modules.

"File "C:\pyinstaller\PyInstaller\loader\iu.py", line 468, in
importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named _fontdata_enc_winansi"

( detailed error below)

Googling around I found that the same issue plagues py2exe apps as
well and in that case the solution is to force the import of the
missing modules in the code.  If I force the import the resulting
*.exe from PyInstaller file works just great.

for eg.

from reportlab.pdfbase import _fontdata_enc_winansi
from reportlab.pdfbase import _fontdata_enc_macroman

My question is :
I started reading the PyInstaller documentation and came across hooks
and the spec file. I am not sure which of these is a way to solve my
particular problem and not have to modify my code to force the import.

Thanks
Hari

############
Detailed error during running the *.exe without
"from reportlab.pdfbase import _fontdata_enc_winansi" statements
############

Traceback (most recent call last):
  File "<string>", line 493, in set_plate_config
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 449, in
importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\gridder.maste
rplate", line 15, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 449, in
importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\gridder.pdfwr
iterlandscape", line 6, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 490, in
importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\reportlab.pdf
gen.canvas", line 25, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 490, in
importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\reportlab.pdf
base.pdfdoc", line 22, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 490, in
importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\reportlab.pdf
base.pdfmetrics", line 23, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 490, in
importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 539, in
doimport
    exec co in mod.__dict__
  File "C:\pyinstaller\gzilla\build\pyi.win32\gzilla\out01-PYZ.pyz
\reportlab.pdf
base._fontdata", line 158, in <module>
  File "C:\pyinstaller\PyInstaller\loader\iu.py", line 468, in
importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named _fontdata_enc_winansi