1

我正在尝试为我的项目生成一个 exe。大约一个月前,当我的项目没有使用 ReportLab 时,它没有问题,但现在,没有那么多了。

搜索后,我发现问题是其中一个 pyinstaller 文件中缺少导入。问题解决了吗?不完全是。

现在我得到这个错误......

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

环顾四周,我发现仅导致了一个建议的解决方案,即强制在我的代码文件中进行所有导入。我有太多的报告文件,让我什至很难考虑这样做。

我读了一些关于隐藏进口的东西。也许这可以帮助我,但我不知道。任何帮助,将不胜感激。谢谢你。

编辑:py2exe 的类似问题和解决方案....

4

2 回答 2

4

我不知道这是否是正确的做法……但我开始拔头发了。

在阅读并浪费了很多时间之后,...

我发现某人的帖子建议将整个丢失的库文件夹(在我的情况下是在我的 pythonxx 的站点包中)复制到包含 exe 的文件夹中。瓦拉!有效。

如果有更好/正确的方法来做到这一点,请赐教。

于 2013-09-02T14:07:17.867 回答
1

添加一个名为hook-reportlab.pdfbase._fontdata.pypyinstaller 的 hooks 子目录的文件。内容应该是这样的:

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

这对我来说适用于 pyinstaller 2.1。顺便说一句,我从默认安装的 pyinstaller 1.5.1 借用了这个文件。

于 2014-01-23T17:30:32.103 回答