2013-07-12 32 views
2

我已经使用pyBarcode库在我的软件中生成条形码,其工作完美正常,但是我从命令行加载它,但是一旦我使用py2exe冻结整个软件,我是生成条形码时出现IO错误。IO错误:使用py2exe在冻结后生成条形码时无法打开图像

File "panels.pyc", line 383, in generate 
File "barcodeGenerator.pyc", line 9, in generate 
File "barcode\base.pyc", line 68, in save 
File "barcode\codex.pyc", line 251, in render 
File "barcode\base.pyc", line 103, in render 
File "barcode\writer.pyc", line 188, in render 
File "barcode\writer.pyc", line 280, in _paint_text 
File "PIL\ImageFont.pyc", line 248, in truetype 
File "PIL\ImageFont.pyc", line 146, in __init__ 
IOError: cannot open resource 

这里的panels.py是我从哪里调用生成barcodeGenerator.py方法的代码如下的python脚本。

barcodeGenerator.py: -

import barcode 
from barcode import generate 
from barcode.writer import ImageWriter 
from PIL import PngImagePlugin 

def generate(details,path): 
    EAN = barcode.get_barcode_class('code128') 
    ean = EAN(details, writer=ImageWriter()) 
    barcodePic = ean.save(path + 'barcode') 

而且是使用setup.py文件是冻结是: -

from distutils.core import setup 
import py2exe 

includes = ["HuffmanDictionary"] 

setup(
options = { 
      "py2exe": {"includes": includes} 
      }, 
console=['MainFrame.py',"extraModules.py","encode.py","decode.py","panels.py","barcodeGenerator.py" ] 
) 

请替某一个点上的错误,我made.I很接近完成整个软件这是最后一个bug,我正在使用Windows 7 64位。

编辑:已经去过这link并尝试但仍然不适合我。

回答

-1

最后在深入探究google并在py2exe的邮件列表上提问后,我意识到py2exe中有一些错误,它没有任何理由就没有包含某些模块。因此,我将整个模块作为include_package添加到.exe文件夹中,并且充当魅力。另外cx_Freeze是使用py2exe的一个很好的选择,因为它易于使用并且在多个平台上受支持。

希望这可以帮助其他在互联网上浪费时间搜索的人。

+1

你能提供一些有关你的py2exe解决方案的更多信息吗?我有同样的问题,并且我已将整个条形码模块包含在配置文件中,但我仍然收到此错误。你的py2exe配置是什么样的? – Andy

1

我发现这个在[Python安装目录] \ LIB \站点包\条码\ writer.py

PATH = os.path.dirname(os.path.abspath(__file__)) 
FONT = os.path.join(PATH, 'DejaVuSansMono.ttf') 

DejaVuSansMono.ttf也是在同一个目录。 但是,在建立cx_freeze之后,条形码编写器会向ImageFont提供无效的字体路径。

我的解决方法是将DejaVuSansMono.ttf复制到PC上的Windows\Fonts OS文件夹,该文件夹将运行您的内置可执行文件。

How I can load a font file with PIL.ImageFont.truetype without specifying the absolute path?

类似问题的另一个解决办法是修改条形码\ writer.py

#FONT = os.path.join(PATH, 'DejaVuSansMono.ttf') 
FONT = 'arial.ttf' 

我觉得ARIAL.TTF应该在每Windows\Fonts(默认字体路径)目录。

+0

也确保在py2exe软件包选项中包含PIL – user2682863

相关问题