IO错误:使用py2exe冻结后,在生成条形码时无法打开图像 [英] IO Error:Cannot open image while generating barcode after freezing using py2exe

查看:101
本文介绍了IO错误:使用py2exe冻结后,在生成条形码时无法打开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用pyBarcode库在我的软件中生成条形码,并且从命令行加载它时,它的工作情况非常好,但是一旦我使用py2exe冻结了整个软件,在生成条形码时就会出现IO错误.

I have used pyBarcode library to generate Barcode in my software and its works perfectly fine while I load it from command line but once I freeze the entire software using py2exe I am getting IO error while generating the barcode.

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是我的python脚本,在这里我可以调用barcodeGenerator.py的生成方法,其代码如下.

Here panels.py is my python script from where I call generate method of barcodeGenerator.py whose code is given below.

barcodeGenerator.py:-

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文件是:-

And yes the setup.py file using which is freeze is:-

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" ]
)

请指出我犯的错误.我非常接近完成整个软件,这是最后一个错误,并且我使用的是Windows 7 64位.

Please could some one point the error I made.I am very close to completing the entire software this is the last bug and I am using windows 7 64 bit.

已经去过这个链接,并尝试过但仍然对我不起作用

Already have been to this link and tried but still not working for me.

推荐答案

最后,在深入研究Google并在py2exe邮件列表中提出问题后,我意识到py2exe中存在一些错误,只是它不包含某些模块没有任何理由.因此,我将整个模块添加为.exe文件夹中的include_package,并且将其作为附件使用.另外,由于cx_Freeze易于使用且在多个平台上受支持,因此它是使用py2exe的不错选择.

Finally after digging deep into google and asking question on the mailing lists of py2exe I realized that there was some error in py2exe it just didn't include the some modules without any reason. So I added the entire module in the folder of .exe as include_package and that worked as a charm. Also cx_Freeze is a good alternative to using py2exe since it is easy to use and is supported on multiple platform.

希望这可以帮助那些浪费时间在Internet上搜索的人.

Hope this helps other who are wasting time searching on internet.

这篇关于IO错误:使用py2exe冻结后,在生成条形码时无法打开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆