2

I'm trying to generate an exe for my project. It worked without problems about a month back when my project didn't use ReportLab, but now, not so much.

After searching through, I found that the problem was a missing import in one of the pyinstaller files. Problem Solved right? Not exactly.

Now I get this error...

Traceback (most recent call last):
File "<string>", line 18, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in importHook 
mod = _self_doimport(nm, ctx, fqname)
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
exec co in mod.__dict__
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\myproject\build\pyi.win32\myproject\out00-PYZ.pyz\reports.My_Report_File", line 10, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 431, in importHook
mod = self.doimport(nm, ctx, ctx + '.' + nm)
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
exec co in mod.__dict__
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\myproject\build\pyi.win32\myproject\out00-PYZ.pyz\reportlab.pdfgen.canvas", line 25, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 431, in importHook
mod = self.doimport(nm, ctx, ctx + '.' + nm)
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
exec co in mod.__dict__
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\myproject\build\pyi.win32\myproject\out00-PYZ.pyz\reportlab.pdfbase.pdfdoc", line 22, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 431, in importHook
mod = self.doimport(nm, ctx, ctx + '.' + nm)
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
exec co in mod.__dict__
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\myproject\build\pyi.win32\myproject\out00-PYZ.pyz\reportlab.pdfbase.pdfmetrics", line 23, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 431, in importHook
mod = self.doimport(nm, ctx, ctx + '.' + nm)
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
exec co in mod.__dict__
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\myproject\build\pyi.win32\myproject\out00-PYZ.pyz\reportlab.pdfbase._fontdata", line 158, in <module>
File "F:\Python\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook
raise ImportError("No module named %s" % fqname)
ImportError: No module named _fontdata_enc_winansi

Searching around, I found this leading to only one proposed solution which was to force all the imports in my code files. I have way too many report files making it difficult for me to even think about doing that.

I read something about hidden imports. Maybe that may help me out, but I don't know. Any help would be appreciated. Thank you.

Edit: A similar problem and solution for py2exe....

Community
  • 1
  • 1
Ryan
  • 269
  • 1
  • 3
  • 15
  • Looks like this question has already been addressed: http://stackoverflow.com/questions/6786473/import-error-while-bundling-using-py2exe – Mike Vella Sep 02 '13 at 12:22
  • @MikeVella that link is for py2exe. I don't understand how this helps me. I've mentioned the link in the question though. – Ryan Sep 02 '13 at 12:31
  • Have you tried the suggestion by robots.jpg in that answer? What happened when you did? – Mike Vella Sep 02 '13 at 12:33
  • @MikeVella i inserted the packages list in my spec file and generated from that, same error – Ryan Sep 02 '13 at 12:50

2 Answers2

5

I don't know if I this is the proper way to do it... but I'm starting to pull my hair out.

After reading around and wasting a bunch of time, ...

I found a post by someone which suggests copying the whole missing library folder (in my case it was in site-packages of my pythonxx) into the folder containing the exe. Walla! It worked.

If there is a better/proper way to do this, please enlighten me.

Ryan
  • 269
  • 1
  • 3
  • 15
1

Add a file named hook-reportlab.pdfbase._fontdata.py to the hooks subdirectory of pyinstaller. The conten should read like this:

hiddenimports = [
    '_fontdata_enc_macexpert',
    '_fontdata_enc_macroman',
    '_fontdata_enc_pdfdoc',
    '_fontdata_enc_standard',
    '_fontdata_enc_symbol',
    '_fontdata_enc_winansi',
    '_fontdata_enc_zapfdingbats',
    '_fontdata_widths_courier',
    '_fontdata_widths_courierbold',
    '_fontdata_widths_courierboldoblique',
    '_fontdata_widths_courieroblique',
    '_fontdata_widths_helvetica',
    '_fontdata_widths_helveticabold',
    '_fontdata_widths_helveticaboldoblique',
    '_fontdata_widths_helveticaoblique',
    '_fontdata_widths_symbol',
    '_fontdata_widths_timesbold',
    '_fontdata_widths_timesbolditalic',
    '_fontdata_widths_timesitalic',
    '_fontdata_widths_timesroman',
    '_fontdata_widths_zapfdingbats']

This worked for me with pyinstaller 2.1. BTW, I borrowed this file from pyinstaller 1.5.1 where it was installed by default.

user819619
  • 11
  • 1