简体   繁体   English

文件转换为exe不能生成条码

[英]File converted to exe can't generate barcode

I tried to generate barcode and made a GUI using pyqt5 when I run it through scripts it works perfectly but when I converted the.py file to.exe file when I try to generate it, it gives many tracebacks当我通过脚本运行它时,我尝试使用 pyqt5 生成条形码并制作了一个 GUI,但是当我尝试生成它时将 .py 文件转换为 .exe 文件时,它给出了许多回溯

import pkg_resources.py2_warn
from PyQt5 import QtCore, QtGui, QtWidgets
import barcode
from barcode.writer import ImageWriter
import shutil
import os


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(607, 503)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(-170, 220, 93, 28))
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(130, 180, 311, 80))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        self.lineEdit.setObjectName("lineEdit")
        self.horizontalLayout.addWidget(self.lineEdit)
        self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout.addWidget(self.pushButton_2)
        self.pushButton_2.clicked.connect(lambda: self.testEan(self.lineEdit.text()))
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButton"))
        self.pushButton_2.setText(_translate("Form", "Generate"))

    def testEan(self, i):
        EAN = barcode.get_barcode_class('code128')
        s = '0' * (8 - len(str(i)) - 1) + str(i)
        ean = EAN(s, writer=ImageWriter())
        fullname = ean.save(str(i))
        try:
            os.mkdir("Barcode")
        except FileExistsError:
            pass
        try:
            shutil.move(fullname, "Barcode")
        except:
            pass
        QtWidgets.QMessageBox().about(QtWidgets.QWidget(), "Info", "Success")


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

NOTE: I have imported pkg_resources.py2_warn because without it when i try to execute the application it throws no module name pkg_resources.py2_warn注意:我已经导入pkg_resources.py2_warn ,因为没有它,当我尝试执行应用程序时,它不会抛出任何模块名称pkg_resources.py2_warn


Traceback: (most recent call last)
 File "Bar.py" line 37, in <lambda>
 File "Bar.py" line 51, in testEan
 File "site packages\barcode\base.py" line 68 in save
 File "site packages\barcode\codex.py" line 261 in render
 File "site packages\barcode\base.py" line 111 in render
 File "site packages\barcode\writer.py" line 226 in render
 File "site packages\barcode\writer.py" line 356 in _paint_text
 File "site packages\PIL\ImageFont.py" line 648 in truetype
 File "site packages\PIL\ImageFont.py" line 645 in freetype
 File "site packages\PIL\ImageFont.py" line 193 in __init__
OsError : cannot open resource

OS          : windows 10
Python      : 3.8.3
Pyinstaller : 3.6

Is there any way to overcome that traceback error?有什么办法可以克服这个回溯错误吗?

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

as stated here you should alter or include the font in you code, so it can read it.如此处所述,您应该在代码中更改或包含字体,以便它可以读取它。 I chosed to alter the code to a "standard" font instead.我选择将代码更改为“标准”字体。

i posted in a similar issue on the repo as well: https://github.com/WhyNotHugo/python-barcode/issues/69我也在 repo 上发布了一个类似的问题: https://github.com/WhyNotHugo/python-barcode/issues/69

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .py文件有效,转换后的.exe文件无效 - .py file works, converted .exe file doesn't 与cmd交互的.py文件是否可以转换为.exe文件 - whether an .py file which is interacting with cmd can be converted to .exe file exe(从python文件转换)可以执行批处理代码吗? - Can an exe(converted from a python file) execute batch codes? 我的文件没有被转换成 exe - My file is not being converted into an exe 为什么将 a.py 文件转换为已转换的可执行文件的 a.exe 文件不起作用? - Why converting a .py file to a .exe file with an already converted executable file doesn't work? 无法将python文件转换为exe文件 - Can't convert python file to exe file 使用pyzbar无法读取同一图像文件中的第二个条形码 - Can't read second barcode in the same image file using pyzbar 无法将 .py 文件转换为 .exe 文件 - Can't make a .py file into a .exe file 我已将 python 程序转换为 .exe 文件,但在打开 .exe 文件时我没有看到 output,而只是一个空的 ZDFFF0A7FA1A55C8C1A4966C19F6DA4520FB2444 - i have converted python program to an .exe file but on opening the .exe file i don't see an output, but just a empty cmd window 如何使用变量生成带有 python-barcode 的条码 - How can I use a variable to generate barcode with python-barcode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM