我已经使用 pyBarcode 库在我的软件中生成条形码,当我从命令行加载它时它的工作非常好,但是一旦我使用 py2exe 冻结整个软件,我在生成条形码时遇到 IO 错误。
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 的generate 方法,其代码如下。
条码生成器.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" ]
)
请指出我犯的错误。我非常接近完成整个软件,这是最后一个错误,我使用的是 Windows 7 64 位。
编辑:已经到过这个链接并尝试过,但仍然不适合我。