我使用py2exe捆绑了一个用python编写的小脚本。该脚本使用许多包,其中一个是reportlab。 使用py2exe捆绑后,我尝试运行可执行文件,并返回以下错误:
C:\Python26\dist>DELchek.exe
Traceback (most recent call last):
File "DELchek.py", line 12, in <module>
File "reportlab\pdfgen\canvas.pyc", line 25, in <
File "reportlab\pdfbase\pdfdoc.pyc", line 22, in
File "reportlab\pdfbase\pdfmetrics.pyc", line 23,
File "reportlab\pdfbase\_fontdata.pyc", line 158,
ImportError: No module named _fontdata_enc_winansi
但我可以在reportlab文件夹中看到'_fontdata_enc_winansi'模块。有人可以帮我解决这个问题。
答案 0 :(得分:13)
我在过去使用py2exe捆绑reportlab时遇到了同样的问题。它动态导入一堆模块,py2exe在组装依赖项时无法识别。强力修复是直接在您的代码中导入所需的模块:
from reportlab.pdfbase import _fontdata_enc_winansi
from reportlab.pdfbase import _fontdata_enc_macroman
from reportlab.pdfbase import _fontdata_enc_standard
from reportlab.pdfbase import _fontdata_enc_symbol
from reportlab.pdfbase import _fontdata_enc_zapfdingbats
from reportlab.pdfbase import _fontdata_enc_pdfdoc
from reportlab.pdfbase import _fontdata_enc_macexpert
from reportlab.pdfbase import _fontdata_widths_courier
from reportlab.pdfbase import _fontdata_widths_courierbold
from reportlab.pdfbase import _fontdata_widths_courieroblique
from reportlab.pdfbase import _fontdata_widths_courierboldoblique
from reportlab.pdfbase import _fontdata_widths_helvetica
from reportlab.pdfbase import _fontdata_widths_helveticabold
from reportlab.pdfbase import _fontdata_widths_helveticaoblique
from reportlab.pdfbase import _fontdata_widths_helveticaboldoblique
from reportlab.pdfbase import _fontdata_widths_timesroman
from reportlab.pdfbase import _fontdata_widths_timesbold
from reportlab.pdfbase import _fontdata_widths_timesitalic
from reportlab.pdfbase import _fontdata_widths_timesbolditalic
from reportlab.pdfbase import _fontdata_widths_symbol
from reportlab.pdfbase import _fontdata_widths_zapfdingbats
搜索还显示Sankar找到another solution,其中包含设置脚本中的以下包:
packages=[
'reportlab',
'reportlab.graphics.charts',
'reportlab.graphics.samples',
'reportlab.graphics.widgets',
'reportlab.graphics.barcode',
'reportlab.graphics',
'reportlab.lib',
'reportlab.pdfbase',
'reportlab.pdfgen',
'reportlab.platypus',
],
答案 1 :(得分:2)
如果您不使用它们,请跳过图片...
packages= [
'reportlab',
'reportlab.lib',
'reportlab.pdfbase',
'reportlab.pdfgen',
'reportlab.platypus',
]
setup(name='pitman',
version='1.0',
author='cue',
data_files = dataFiles,
console=['xxx.py', 'yyy.py'], # change to windows=[...]
options = {
"py2exe": { "dll_excludes": ["MSVCP90.dll"],
"packages": packages,
"includes": includes }
}
)