zoukankan      html  css  js  c++  java
  • py2exe issue: ImportError: No module named _fontdata_enc_winansi (http://stackoverflow.com/)

    Q:

    I bundled a small script written in python using py2exe. The script uses many packages and one of them is reportlab. After bundling using py2exe I tried to run the executable file and it is returning following error:

    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:Nomodule named _fontdata_enc_winansi

    But I could see the '_fontdata_enc_winansi' module in reportlab folder. Could someone help me to fix this.

    A:

    I've had the same problem in the past bundling reportlab with py2exe. It imports of a bunch of modules dynamically, which py2exe does not recognize when assembling the dependencies. The brute-force fix is to import the required modules directly in your code:

    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


    A search also shows that Sankar found another solution, which is including the following packages in the setup script:

    packages=[
    'reportlab',
    'reportlab.graphics.charts',
    'reportlab.graphics.samples',
    'reportlab.graphics.widgets',
    'reportlab.graphics.barcode',
    'reportlab.graphics',
    'reportlab.lib',
    'reportlab.pdfbase',
    'reportlab.pdfgen',
    'reportlab.platypus',
    ],


      

     
  • 相关阅读:
    SQL Server数据库高级进阶之事务实战演练
    ASP.NET Core使用Nginx搭建高可用分布式Web集群
    C#签名算法HS256和RS256实战演练
    ASP.NET (Core)WebApi参数传递实操演练
    基于Windows服务实现的亚马逊云S3文件上传
    ASP.NET Core WebApi如何动态生成树形Json格式数据
    SQL Server数据库高级进阶之分布式唯一ID生成实战演练
    ASP.NET Core WebApi分布式文件系统FastDFS实战演练
    .Net Core使用NLog记录日志到文件和数据库实战演练
    ASP.NET Core开源任务调度框架Hangfire实战演练
  • 原文地址:https://www.cnblogs.com/yangyingchao/p/2263777.html
Copyright © 2011-2022 走看看