Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top