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

已查看 610 次
跳至第一个未读帖子

harijay

未读,
2012年1月25日 16:32:532012/1/25
收件人 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

Martin Zibricky

未读,
2012年2月2日 11:07:422012/2/2
收件人 pyins...@googlegroups.com
harijay píše v St 25. 01. 2012 v 13:32 -0800:

> 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.

I think the right way would be a hook with variable 'hiddenimport'.

回复全部
回复作者
转发
0 个新帖子